l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

perl.js (5119B)


      1 /*
      2 Language: Perl
      3 Author: Peter Leonov <gojpeg@yandex.ru>
      4 Website: https://www.perl.org
      5 Category: common
      6 */
      7 
      8 function perl(hljs) {
      9   var PERL_KEYWORDS = {
     10     $pattern: /[\w.]+/,
     11     keyword: 'getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ' +
     12     'ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime ' +
     13     'readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qq ' +
     14     'fileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent ' +
     15     'shutdown dump chomp connect getsockname die socketpair close flock exists index shmget ' +
     16     'sub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr ' +
     17     'unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 ' +
     18     'getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline ' +
     19     'endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand ' +
     20     'mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink ' +
     21     'getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr ' +
     22     'untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link ' +
     23     'getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller ' +
     24     'lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and ' +
     25     'sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 ' +
     26     'chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach ' +
     27     'tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedir ' +
     28     'ioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe ' +
     29     'atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when'
     30   };
     31   var SUBST = {
     32     className: 'subst',
     33     begin: '[$@]\\{', end: '\\}',
     34     keywords: PERL_KEYWORDS
     35   };
     36   var METHOD = {
     37     begin: '->{', end: '}'
     38     // contains defined later
     39   };
     40   var VAR = {
     41     variants: [
     42       {begin: /\$\d/},
     43       {begin: /[\$%@](\^\w\b|#\w+(::\w+)*|{\w+}|\w+(::\w*)*)/},
     44       {begin: /[\$%@][^\s\w{]/, relevance: 0}
     45     ]
     46   };
     47   var STRING_CONTAINS = [hljs.BACKSLASH_ESCAPE, SUBST, VAR];
     48   var PERL_DEFAULT_CONTAINS = [
     49     VAR,
     50     hljs.HASH_COMMENT_MODE,
     51     hljs.COMMENT(
     52       '^\\=\\w',
     53       '\\=cut',
     54       {
     55         endsWithParent: true
     56       }
     57     ),
     58     METHOD,
     59     {
     60       className: 'string',
     61       contains: STRING_CONTAINS,
     62       variants: [
     63         {
     64           begin: 'q[qwxr]?\\s*\\(', end: '\\)',
     65           relevance: 5
     66         },
     67         {
     68           begin: 'q[qwxr]?\\s*\\[', end: '\\]',
     69           relevance: 5
     70         },
     71         {
     72           begin: 'q[qwxr]?\\s*\\{', end: '\\}',
     73           relevance: 5
     74         },
     75         {
     76           begin: 'q[qwxr]?\\s*\\|', end: '\\|',
     77           relevance: 5
     78         },
     79         {
     80           begin: 'q[qwxr]?\\s*\\<', end: '\\>',
     81           relevance: 5
     82         },
     83         {
     84           begin: 'qw\\s+q', end: 'q',
     85           relevance: 5
     86         },
     87         {
     88           begin: '\'', end: '\'',
     89           contains: [hljs.BACKSLASH_ESCAPE]
     90         },
     91         {
     92           begin: '"', end: '"'
     93         },
     94         {
     95           begin: '`', end: '`',
     96           contains: [hljs.BACKSLASH_ESCAPE]
     97         },
     98         {
     99           begin: '{\\w+}',
    100           contains: [],
    101           relevance: 0
    102         },
    103         {
    104           begin: '\-?\\w+\\s*\\=\\>',
    105           contains: [],
    106           relevance: 0
    107         }
    108       ]
    109     },
    110     {
    111       className: 'number',
    112       begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
    113       relevance: 0
    114     },
    115     { // regexp container
    116       begin: '(\\/\\/|' + hljs.RE_STARTERS_RE + '|\\b(split|return|print|reverse|grep)\\b)\\s*',
    117       keywords: 'split return print reverse grep',
    118       relevance: 0,
    119       contains: [
    120         hljs.HASH_COMMENT_MODE,
    121         {
    122           className: 'regexp',
    123           begin: '(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*',
    124           relevance: 10
    125         },
    126         {
    127           className: 'regexp',
    128           begin: '(m|qr)?/', end: '/[a-z]*',
    129           contains: [hljs.BACKSLASH_ESCAPE],
    130           relevance: 0 // allows empty "//" which is a common comment delimiter in other languages
    131         }
    132       ]
    133     },
    134     {
    135       className: 'function',
    136       beginKeywords: 'sub', end: '(\\s*\\(.*?\\))?[;{]', excludeEnd: true,
    137       relevance: 5,
    138       contains: [hljs.TITLE_MODE]
    139     },
    140     {
    141       begin: '-\\w\\b',
    142       relevance: 0
    143     },
    144     {
    145       begin: "^__DATA__$",
    146       end: "^__END__$",
    147       subLanguage: 'mojolicious',
    148       contains: [
    149         {
    150             begin: "^@@.*",
    151             end: "$",
    152             className: "comment"
    153         }
    154       ]
    155     }
    156   ];
    157   SUBST.contains = PERL_DEFAULT_CONTAINS;
    158   METHOD.contains = PERL_DEFAULT_CONTAINS;
    159 
    160   return {
    161     name: 'Perl',
    162     aliases: ['pl', 'pm'],
    163     keywords: PERL_KEYWORDS,
    164     contains: PERL_DEFAULT_CONTAINS
    165   };
    166 }
    167 
    168 module.exports = perl;