Debian Codegraph @

codemirror-legacy-modes/mode/perl.js

raw
1
2 // it's like "peek", but need for look-ahead or look-behind if index < 0
3 function look(stream, c){
4 return stream.string.charAt(stream.pos+(c||0));
5 }
6
7 // return a part of prefix of current stream from current position
8 function prefix(stream, c){
9 if(c){
10 var x=stream.pos-c;
11 return stream.string.substr((x>=0?x:0),c);}
12 else{
13 return stream.string.substr(0,stream.pos-1);
14 }
15 }
16
17 // return a part of suffix of current stream from current position
18 function suffix(stream, c){
19 var y=stream.string.length;
20 var x=y-stream.pos+1;
21 return stream.string.substr(stream.pos,(c&&c<y?c:x));
22 }
23
24 // eating and vomiting a part of stream from current position
25 function eatSuffix(stream, c){
26 var x=stream.pos+c;
27 var y;
28 if(x<=0)
29 stream.pos=0;
30 else if(x>=(y=stream.string.length-1))
31 stream.pos=y;
32 else
33 stream.pos=x;
34 }
35
36 // http://perldoc.perl.org
37 var PERL={ // null - magic touch
38 // 1 - keyword
39 // 2 - def
40 // 3 - atom
41 // 4 - operator
42 // 5 - builtin (predefined)
43 // [x,y] - x=1,2,3; y=must be defined if x{...}
44 // PERL operators
45 '->': 4,
46 '++': 4,
47 '--': 4,
48 '**': 4,
49 // ! ~ \ and unary + and -
50 '=~': 4,
51 '!~': 4,
52 '*': 4,
53 '/': 4,
54 '%': 4,
55 'x': 4,
56 '+': 4,
57 '-': 4,
58 '.': 4,
59 '<<': 4,
60 '>>': 4,
61 // named unary operators
62 '<': 4,
63 '>': 4,
64 '<=': 4,
65 '>=': 4,
66 'lt': 4,
67 'gt': 4,
68 'le': 4,
69 'ge': 4,
70 '==': 4,
71 '!=': 4,
72 '<=>': 4,
73 'eq': 4,
74 'ne': 4,
75 'cmp': 4,
76 '~~': 4,
77 '&': 4,
78 '|': 4,
79 '^': 4,
80 '&&': 4,
81 '||': 4,
82 '//': 4,
83 '..': 4,
84 '...': 4,
85 '?': 4,
86 ':': 4,
87 '=': 4,
88 '+=': 4,
89 '-=': 4,
90 '*=': 4, // etc. ???
91 ',': 4,
92 '=>': 4,
93 '::': 4,
94 // list operators (rightward)
95 'not': 4,
96 'and': 4,
97 'or': 4,
98 'xor': 4,
99 // PERL predefined variables (I know, what this is a paranoid idea, but may be needed for people, who learn PERL, and for me as well, ...and may be for you?;)
100 'BEGIN': [5,1],
101 'END': [5,1],
102 'PRINT': [5,1],
103 'PRINTF': [5,1],
104 'GETC': [5,1],
105 'READ': [5,1],
106 'READLINE': [5,1],
107 'DESTROY': [5,1],
108 'TIE': [5,1],
109 'TIEHANDLE': [5,1],
110 'UNTIE': [5,1],
111 'STDIN': 5,
112 'STDIN_TOP': 5,
113 'STDOUT': 5,
114 'STDOUT_TOP': 5,
115 'STDERR': 5,
116 'STDERR_TOP': 5,
117 '$ARG': 5,
118 '$_': 5,
119 '@ARG': 5,
120 '@_': 5,
121 '$LIST_SEPARATOR': 5,
122 '$"': 5,
123 '$PROCESS_ID': 5,
124 '$PID': 5,
125 '$$': 5,
126 '$REAL_GROUP_ID': 5,
127 '$GID': 5,
128 '$(': 5,
129 '$EFFECTIVE_GROUP_ID': 5,
130 '$EGID': 5,
131 '$)': 5,
132 '$PROGRAM_NAME': 5,
133 '$0': 5,
134 '$SUBSCRIPT_SEPARATOR': 5,
135 '$SUBSEP': 5,
136 '$;': 5,
137 '$REAL_USER_ID': 5,
138 '$UID': 5,
139 '$<': 5,
140 '$EFFECTIVE_USER_ID': 5,
141 '$EUID': 5,
142 '$>': 5,
143 '$a': 5,
144 '$b': 5,
145 '$COMPILING': 5,
146 '$^C': 5,
147 '$DEBUGGING': 5,
148 '$^D': 5,
149 '${^ENCODING}': 5,
150 '$ENV': 5,
151 '%ENV': 5,
152 '$SYSTEM_FD_MAX': 5,
153 '$^F': 5,
154 '@F': 5,
155 '${^GLOBAL_PHASE}': 5,
156 '$^H': 5,
157 '%^H': 5,
158 '@INC': 5,
159 '%INC': 5,
160 '$INPLACE_EDIT': 5,
161 '$^I': 5,
162 '$^M': 5,
163 '$OSNAME': 5,
164 '$^O': 5,
165 '${^OPEN}': 5,
166 '$PERLDB': 5,
167 '$^P': 5,
168 '$SIG': 5,
169 '%SIG': 5,
170 '$BASETIME': 5,
171 '$^T': 5,
172 '${^TAINT}': 5,
173 '${^UNICODE}': 5,
174 '${^UTF8CACHE}': 5,
175 '${^UTF8LOCALE}': 5,
176 '$PERL_VERSION': 5,
177 '$^V': 5,
178 '${^WIN32_SLOPPY_STAT}': 5,
179 '$EXECUTABLE_NAME': 5,
180 '$^X': 5,
181 '$1': 5, // - regexp $1, $2...
182 '$MATCH': 5,
183 '$&': 5,
184 '${^MATCH}': 5,
185 '$PREMATCH': 5,
186 '$`': 5,
187 '${^PREMATCH}': 5,
188 '$POSTMATCH': 5,
189 "$'": 5,
190 '${^POSTMATCH}': 5,
191 '$LAST_PAREN_MATCH': 5,
192 '$+': 5,
193 '$LAST_SUBMATCH_RESULT': 5,
194 '$^N': 5,
195 '@LAST_MATCH_END': 5,
196 '@+': 5,
197 '%LAST_PAREN_MATCH': 5,
198 '%+': 5,
199 '@LAST_MATCH_START': 5,
200 '@-': 5,
201 '%LAST_MATCH_START': 5,
202 '%-': 5,
203 '$LAST_REGEXP_CODE_RESULT': 5,
204 '$^R': 5,
205 '${^RE_DEBUG_FLAGS}': 5,
206 '${^RE_TRIE_MAXBUF}': 5,
207 '$ARGV': 5,
208 '@ARGV': 5,
209 'ARGV': 5,
210 'ARGVOUT': 5,
211 '$OUTPUT_FIELD_SEPARATOR': 5,
212 '$OFS': 5,
213 '$,': 5,
214 '$INPUT_LINE_NUMBER': 5,
215 '$NR': 5,
216 '$.': 5,
217 '$INPUT_RECORD_SEPARATOR': 5,
218 '$RS': 5,
219 '$/': 5,
220 '$OUTPUT_RECORD_SEPARATOR': 5,
221 '$ORS': 5,
222 '$\\': 5,
223 '$OUTPUT_AUTOFLUSH': 5,
224 '$|': 5,
225 '$ACCUMULATOR': 5,
226 '$^A': 5,
227 '$FORMAT_FORMFEED': 5,
228 '$^L': 5,
229 '$FORMAT_PAGE_NUMBER': 5,
230 '$%': 5,
231 '$FORMAT_LINES_LEFT': 5,
232 '$-': 5,
233 '$FORMAT_LINE_BREAK_CHARACTERS': 5,
234 '$:': 5,
235 '$FORMAT_LINES_PER_PAGE': 5,
236 '$=': 5,
237 '$FORMAT_TOP_NAME': 5,
238 '$^': 5,
239 '$FORMAT_NAME': 5,
240 '$~': 5,
241 '${^CHILD_ERROR_NATIVE}': 5,
242 '$EXTENDED_OS_ERROR': 5,
243 '$^E': 5,
244 '$EXCEPTIONS_BEING_CAUGHT': 5,
245 '$^S': 5,
246 '$WARNING': 5,
247 '$^W': 5,
248 '${^WARNING_BITS}': 5,
249 '$OS_ERROR': 5,
250 '$ERRNO': 5,
251 '$!': 5,
252 '%OS_ERROR': 5,
253 '%ERRNO': 5,
254 '%!': 5,
255 '$CHILD_ERROR': 5,
256 '$?': 5,
257 '$EVAL_ERROR': 5,
258 '$@': 5,
259 '$OFMT': 5,
260 '$#': 5,
261 '$*': 5,
262 '$ARRAY_BASE': 5,
263 '$[': 5,
264 '$OLD_PERL_VERSION': 5,
265 '$]': 5,
266 // PERL blocks
267 'if':[1,1],
268 elsif:[1,1],
269 'else':[1,1],
270 'while':[1,1],
271 unless:[1,1],
272 'for':[1,1],
273 foreach:[1,1],
274 // PERL functions
275 'abs':1, // - absolute value function
276 accept:1, // - accept an incoming socket connect
277 alarm:1, // - schedule a SIGALRM
278 'atan2':1, // - arctangent of Y/X in the range -PI to PI
279 bind:1, // - binds an address to a socket
280 binmode:1, // - prepare binary files for I/O
281 bless:1, // - create an object
282 bootstrap:1, //
283 'break':1, // - break out of a "given" block
284 caller:1, // - get context of the current subroutine call
285 chdir:1, // - change your current working directory
286 chmod:1, // - changes the permissions on a list of files
287 chomp:1, // - remove a trailing record separator from a string
288 chop:1, // - remove the last character from a string
289 chown:1, // - change the ownership on a list of files
290 chr:1, // - get character this number represents
291 chroot:1, // - make directory new root for path lookups
292 close:1, // - close file (or pipe or socket) handle
293 closedir:1, // - close directory handle
294 connect:1, // - connect to a remote socket
295 'continue':[1,1], // - optional trailing block in a while or foreach
296 'cos':1, // - cosine function
297 crypt:1, // - one-way passwd-style encryption
298 dbmclose:1, // - breaks binding on a tied dbm file
299 dbmopen:1, // - create binding on a tied dbm file
300 'default':1, //
301 defined:1, // - test whether a value, variable, or function is defined
302 'delete':1, // - deletes a value from a hash
303 die:1, // - raise an exception or bail out
304 'do':1, // - turn a BLOCK into a TERM
305 dump:1, // - create an immediate core dump
306 each:1, // - retrieve the next key/value pair from a hash
307 endgrent:1, // - be done using group file
308 endhostent:1, // - be done using hosts file
309 endnetent:1, // - be done using networks file
310 endprotoent:1, // - be done using protocols file
311 endpwent:1, // - be done using passwd file
312 endservent:1, // - be done using services file
313 eof:1, // - test a filehandle for its end
314 'eval':1, // - catch exceptions or compile and run code
315 'exec':1, // - abandon this program to run another
316 exists:1, // - test whether a hash key is present
317 exit:1, // - terminate this program
318 'exp':1, // - raise I to a power
319 fcntl:1, // - file control system call
320 fileno:1, // - return file descriptor from filehandle
321 flock:1, // - lock an entire file with an advisory lock
322 fork:1, // - create a new process just like this one
323 format:1, // - declare a picture format with use by the write() function
324 formline:1, // - internal function used for formats
325 getc:1, // - get the next character from the filehandle
326 getgrent:1, // - get next group record
327 getgrgid:1, // - get group record given group user ID
328 getgrnam:1, // - get group record given group name
329 gethostbyaddr:1, // - get host record given its address
330 gethostbyname:1, // - get host record given name
331 gethostent:1, // - get next hosts record
332 getlogin:1, // - return who logged in at this tty
333 getnetbyaddr:1, // - get network record given its address
334 getnetbyname:1, // - get networks record given name
335 getnetent:1, // - get next networks record
336 getpeername:1, // - find the other end of a socket connection
337 getpgrp:1, // - get process group
338 getppid:1, // - get parent process ID
339 getpriority:1, // - get current nice value
340 getprotobyname:1, // - get protocol record given name
341 getprotobynumber:1, // - get protocol record numeric protocol
342 getprotoent:1, // - get next protocols record
343 getpwent:1, // - get next passwd record
344 getpwnam:1, // - get passwd record given user login name
345 getpwuid:1, // - get passwd record given user ID
346 getservbyname:1, // - get services record given its name
347 getservbyport:1, // - get services record given numeric port
348 getservent:1, // - get next services record
349 getsockname:1, // - retrieve the sockaddr for a given socket
350 getsockopt:1, // - get socket options on a given socket
351 given:1, //
352 glob:1, // - expand filenames using wildcards
353 gmtime:1, // - convert UNIX time into record or string using Greenwich time
354 'goto':1, // - create spaghetti code
355 grep:1, // - locate elements in a list test true against a given criterion
356 hex:1, // - convert a string to a hexadecimal number
357 'import':1, // - patch a module's namespace into your own
358 index:1, // - find a substring within a string
359 'int':1, // - get the integer portion of a number
360 ioctl:1, // - system-dependent device control system call
361 'join':1, // - join a list into a string using a separator
362 keys:1, // - retrieve list of indices from a hash
363 kill:1, // - send a signal to a process or process group
364 last:1, // - exit a block prematurely
365 lc:1, // - return lower-case version of a string
366 lcfirst:1, // - return a string with just the next letter in lower case
367 length:1, // - return the number of bytes in a string
368 'link':1, // - create a hard link in the filesystem
369 listen:1, // - register your socket as a server
370 local: 2, // - create a temporary value for a global variable (dynamic scoping)
371 localtime:1, // - convert UNIX time into record or string using local time
372 lock:1, // - get a thread lock on a variable, subroutine, or method
373 'log':1, // - retrieve the natural logarithm for a number
374 lstat:1, // - stat a symbolic link
375 m:null, // - match a string with a regular expression pattern
376 map:1, // - apply a change to a list to get back a new list with the changes
377 mkdir:1, // - create a directory
378 msgctl:1, // - SysV IPC message control operations
379 msgget:1, // - get SysV IPC message queue
380 msgrcv:1, // - receive a SysV IPC message from a message queue
381 msgsnd:1, // - send a SysV IPC message to a message queue
382 my: 2, // - declare and assign a local variable (lexical scoping)
383 'new':1, //
384 next:1, // - iterate a block prematurely
385 no:1, // - unimport some module symbols or semantics at compile time
386 oct:1, // - convert a string to an octal number
387 open:1, // - open a file, pipe, or descriptor
388 opendir:1, // - open a directory
389 ord:1, // - find a character's numeric representation
390 our: 2, // - declare and assign a package variable (lexical scoping)
391 pack:1, // - convert a list into a binary representation
392 'package':1, // - declare a separate global namespace
393 pipe:1, // - open a pair of connected filehandles
394 pop:1, // - remove the last element from an array and return it
395 pos:1, // - find or set the offset for the last/next m//g search
396 print:1, // - output a list to a filehandle
397 printf:1, // - output a formatted list to a filehandle
398 prototype:1, // - get the prototype (if any) of a subroutine
399 push:1, // - append one or more elements to an array
400 q:null, // - singly quote a string
401 qq:null, // - doubly quote a string
402 qr:null, // - Compile pattern
403 quotemeta:null, // - quote regular expression magic characters
404 qw:null, // - quote a list of words
405 qx:null, // - backquote quote a string
406 rand:1, // - retrieve the next pseudorandom number
407 read:1, // - fixed-length buffered input from a filehandle
408 readdir:1, // - get a directory from a directory handle
409 readline:1, // - fetch a record from a file
410 readlink:1, // - determine where a symbolic link is pointing
411 readpipe:1, // - execute a system command and collect standard output
412 recv:1, // - receive a message over a Socket
413 redo:1, // - start this loop iteration over again
414 ref:1, // - find out the type of thing being referenced
415 rename:1, // - change a filename
416 require:1, // - load in external functions from a library at runtime
417 reset:1, // - clear all variables of a given name
418 'return':1, // - get out of a function early
419 reverse:1, // - flip a string or a list
420 rewinddir:1, // - reset directory handle
421 rindex:1, // - right-to-left substring search
422 rmdir:1, // - remove a directory
423 s:null, // - replace a pattern with a string
424 say:1, // - print with newline
425 scalar:1, // - force a scalar context
426 seek:1, // - reposition file pointer for random-access I/O
427 seekdir:1, // - reposition directory pointer
428 select:1, // - reset default output or do I/O multiplexing
429 semctl:1, // - SysV semaphore control operations
430 semget:1, // - get set of SysV semaphores
431 semop:1, // - SysV semaphore operations
432 send:1, // - send a message over a socket
433 setgrent:1, // - prepare group file for use
434 sethostent:1, // - prepare hosts file for use
435 setnetent:1, // - prepare networks file for use
436 setpgrp:1, // - set the process group of a process
437 setpriority:1, // - set a process's nice value
438 setprotoent:1, // - prepare protocols file for use
439 setpwent:1, // - prepare passwd file for use
440 setservent:1, // - prepare services file for use
441 setsockopt:1, // - set some socket options
442 shift:1, // - remove the first element of an array, and return it
443 shmctl:1, // - SysV shared memory operations
444 shmget:1, // - get SysV shared memory segment identifier
445 shmread:1, // - read SysV shared memory
446 shmwrite:1, // - write SysV shared memory
447 shutdown:1, // - close down just half of a socket connection
448 'sin':1, // - return the sine of a number
449 sleep:1, // - block for some number of seconds
450 socket:1, // - create a socket
451 socketpair:1, // - create a pair of sockets
452 'sort':1, // - sort a list of values
453 splice:1, // - add or remove elements anywhere in an array
454 'split':1, // - split up a string using a regexp delimiter
455 sprintf:1, // - formatted print into a string
456 'sqrt':1, // - square root function
457 srand:1, // - seed the random number generator
458 stat:1, // - get a file's status information
459 state:1, // - declare and assign a state variable (persistent lexical scoping)
460 study:1, // - optimize input data for repeated searches
461 'sub':1, // - declare a subroutine, possibly anonymously
462 'substr':1, // - get or alter a portion of a string
463 symlink:1, // - create a symbolic link to a file
464 syscall:1, // - execute an arbitrary system call
465 sysopen:1, // - open a file, pipe, or descriptor
466 sysread:1, // - fixed-length unbuffered input from a filehandle
467 sysseek:1, // - position I/O pointer on handle used with sysread and syswrite
468 system:1, // - run a separate program
469 syswrite:1, // - fixed-length unbuffered output to a filehandle
470 tell:1, // - get current seekpointer on a filehandle
471 telldir:1, // - get current seekpointer on a directory handle
472 tie:1, // - bind a variable to an object class
473 tied:1, // - get a reference to the object underlying a tied variable
474 time:1, // - return number of seconds since 1970
475 times:1, // - return elapsed time for self and child processes
476 tr:null, // - transliterate a string
477 truncate:1, // - shorten a file
478 uc:1, // - return upper-case version of a string
479 ucfirst:1, // - return a string with just the next letter in upper case
480 umask:1, // - set file creation mode mask
481 undef:1, // - remove a variable or function definition
482 unlink:1, // - remove one link to a file
483 unpack:1, // - convert binary structure into normal perl variables
484 unshift:1, // - prepend more elements to the beginning of a list
485 untie:1, // - break a tie binding to a variable
486 use:1, // - load in a module at compile time
487 utime:1, // - set a file's last access and modify times
488 values:1, // - return a list of the values in a hash
489 vec:1, // - test or set particular bits in a string
490 wait:1, // - wait for any child process to die
491 waitpid:1, // - wait for a particular child process to die
492 wantarray:1, // - get void vs scalar vs list context of current subroutine call
493 warn:1, // - print debugging info
494 when:1, //
495 write:1, // - print a picture record
496 y:null}; // - transliterate a string
497
498 var RXstyle="string.special";
499 var RXmodifiers=/[goseximacplud]/; // NOTE: "m", "s", "y" and "tr" need to correct real modifiers for each regexp type
500
501 function tokenChain(stream,state,chain,style,tail){ // NOTE: chain.length > 2 is not working now (it's for s[...][...]geos;)
502 state.chain=null; // 12 3tail
503 state.style=null;
504 state.tail=null;
505 state.tokenize=function(stream,state){
506 var e=false,c,i=0;
507 while(c=stream.next()){
508 if(c===chain[i]&&!e){
509 if(chain[++i]!==undefined){
510 state.chain=chain[i];
511 state.style=style;
512 state.tail=tail;}
513 else if(tail)
514 stream.eatWhile(tail);
515 state.tokenize=tokenPerl;
516 return style;}
517 e=!e&&c=="\\";}
518 return style;};
519 return state.tokenize(stream,state);}
520
521 function tokenSOMETHING(stream,state,string){
522 state.tokenize=function(stream,state){
523 if(stream.string==string)
524 state.tokenize=tokenPerl;
525 stream.skipToEnd();
526 return "string";};
527 return state.tokenize(stream,state);}
528
529 function tokenPerl(stream,state){
530 if(stream.eatSpace())
531 return null;
532 if(state.chain)
533 return tokenChain(stream,state,state.chain,state.style,state.tail);
534 if(stream.match(/^(\-?((\d[\d_]*)?\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F_]+|0b[01_]+|\d[\d_]*(e[+-]?\d+)?)/))
535 return 'number';
536 if(stream.match(/^<<(?=[_a-zA-Z])/)){ // NOTE: <<SOMETHING\n...\nSOMETHING\n
537 stream.eatWhile(/\w/);
538 return tokenSOMETHING(stream,state,stream.current().substr(2));}
539 if(stream.sol()&&stream.match(/^\=item(?!\w)/)){// NOTE: \n=item...\n=cut\n
540 return tokenSOMETHING(stream,state,'=cut');}
541 var ch=stream.next();
542 if(ch=='"'||ch=="'"){ // NOTE: ' or " or <<'SOMETHING'\n...\nSOMETHING\n or <<"SOMETHING"\n...\nSOMETHING\n
543 if(prefix(stream, 3)=="<<"+ch){
544 var p=stream.pos;
545 stream.eatWhile(/\w/);
546 var n=stream.current().substr(1);
547 if(n&&stream.eat(ch))
548 return tokenSOMETHING(stream,state,n);
549 stream.pos=p;}
550 return tokenChain(stream,state,[ch],"string");}
551 if(ch=="q"){
552 var c=look(stream, -2);
553 if(!(c&&/\w/.test(c))){
554 c=look(stream, 0);
555 if(c=="x"){
556 c=look(stream, 1);
557 if(c=="("){
558 eatSuffix(stream, 2);
559 return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
560 if(c=="["){
561 eatSuffix(stream, 2);
562 return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
563 if(c=="{"){
564 eatSuffix(stream, 2);
565 return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
566 if(c=="<"){
567 eatSuffix(stream, 2);
568 return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
569 if(/[\^'"!~\/]/.test(c)){
570 eatSuffix(stream, 1);
571 return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
572 else if(c=="q"){
573 c=look(stream, 1);
574 if(c=="("){
575 eatSuffix(stream, 2);
576 return tokenChain(stream,state,[")"],"string");}
577 if(c=="["){
578 eatSuffix(stream, 2);
579 return tokenChain(stream,state,["]"],"string");}
580 if(c=="{"){
581 eatSuffix(stream, 2);
582 return tokenChain(stream,state,["}"],"string");}
583 if(c=="<"){
584 eatSuffix(stream, 2);
585 return tokenChain(stream,state,[">"],"string");}
586 if(/[\^'"!~\/]/.test(c)){
587 eatSuffix(stream, 1);
588 return tokenChain(stream,state,[stream.eat(c)],"string");}}
589 else if(c=="w"){
590 c=look(stream, 1);
591 if(c=="("){
592 eatSuffix(stream, 2);
593 return tokenChain(stream,state,[")"],"bracket");}
594 if(c=="["){
595 eatSuffix(stream, 2);
596 return tokenChain(stream,state,["]"],"bracket");}
597 if(c=="{"){
598 eatSuffix(stream, 2);
599 return tokenChain(stream,state,["}"],"bracket");}
600 if(c=="<"){
601 eatSuffix(stream, 2);
602 return tokenChain(stream,state,[">"],"bracket");}
603 if(/[\^'"!~\/]/.test(c)){
604 eatSuffix(stream, 1);
605 return tokenChain(stream,state,[stream.eat(c)],"bracket");}}
606 else if(c=="r"){
607 c=look(stream, 1);
608 if(c=="("){
609 eatSuffix(stream, 2);
610 return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
611 if(c=="["){
612 eatSuffix(stream, 2);
613 return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
614 if(c=="{"){
615 eatSuffix(stream, 2);
616 return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
617 if(c=="<"){
618 eatSuffix(stream, 2);
619 return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}
620 if(/[\^'"!~\/]/.test(c)){
621 eatSuffix(stream, 1);
622 return tokenChain(stream,state,[stream.eat(c)],RXstyle,RXmodifiers);}}
623 else if(/[\^'"!~\/(\[{<]/.test(c)){
624 if(c=="("){
625 eatSuffix(stream, 1);
626 return tokenChain(stream,state,[")"],"string");}
627 if(c=="["){
628 eatSuffix(stream, 1);
629 return tokenChain(stream,state,["]"],"string");}
630 if(c=="{"){
631 eatSuffix(stream, 1);
632 return tokenChain(stream,state,["}"],"string");}
633 if(c=="<"){
634 eatSuffix(stream, 1);
635 return tokenChain(stream,state,[">"],"string");}
636 if(/[\^'"!~\/]/.test(c)){
637 return tokenChain(stream,state,[stream.eat(c)],"string");}}}}
638 if(ch=="m"){
639 var c=look(stream, -2);
640 if(!(c&&/\w/.test(c))){
641 c=stream.eat(/[(\[{<\^'"!~\/]/);
642 if(c){
643 if(/[\^'"!~\/]/.test(c)){
644 return tokenChain(stream,state,[c],RXstyle,RXmodifiers);}
645 if(c=="("){
646 return tokenChain(stream,state,[")"],RXstyle,RXmodifiers);}
647 if(c=="["){
648 return tokenChain(stream,state,["]"],RXstyle,RXmodifiers);}
649 if(c=="{"){
650 return tokenChain(stream,state,["}"],RXstyle,RXmodifiers);}
651 if(c=="<"){
652 return tokenChain(stream,state,[">"],RXstyle,RXmodifiers);}}}}
653 if(ch=="s"){
654 var c=/[\/>\]})\w]/.test(look(stream, -2));
655 if(!c){
656 c=stream.eat(/[(\[{<\^'"!~\/]/);
657 if(c){
658 if(c=="[")
659 return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
660 if(c=="{")
661 return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
662 if(c=="<")
663 return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
664 if(c=="(")
665 return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
666 return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
667 if(ch=="y"){
668 var c=/[\/>\]})\w]/.test(look(stream, -2));
669 if(!c){
670 c=stream.eat(/[(\[{<\^'"!~\/]/);
671 if(c){
672 if(c=="[")
673 return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
674 if(c=="{")
675 return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
676 if(c=="<")
677 return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
678 if(c=="(")
679 return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
680 return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}
681 if(ch=="t"){
682 var c=/[\/>\]})\w]/.test(look(stream, -2));
683 if(!c){
684 c=stream.eat("r");if(c){
685 c=stream.eat(/[(\[{<\^'"!~\/]/);
686 if(c){
687 if(c=="[")
688 return tokenChain(stream,state,["]","]"],RXstyle,RXmodifiers);
689 if(c=="{")
690 return tokenChain(stream,state,["}","}"],RXstyle,RXmodifiers);
691 if(c=="<")
692 return tokenChain(stream,state,[">",">"],RXstyle,RXmodifiers);
693 if(c=="(")
694 return tokenChain(stream,state,[")",")"],RXstyle,RXmodifiers);
695 return tokenChain(stream,state,[c,c],RXstyle,RXmodifiers);}}}}
696 if(ch=="`"){
697 return tokenChain(stream,state,[ch],"builtin");}
698 if(ch=="/"){
699 if(!/~\s*$/.test(prefix(stream)))
700 return "operator";
701 else
702 return tokenChain(stream,state,[ch],RXstyle,RXmodifiers);}
703 if(ch=="$"){
704 var p=stream.pos;
705 if(stream.eatWhile(/\d/)||stream.eat("{")&&stream.eatWhile(/\d/)&&stream.eat("}"))
706 return "builtin";
707 else
708 stream.pos=p;}
709 if(/[$@%]/.test(ch)){
710 var p=stream.pos;
711 if(stream.eat("^")&&stream.eat(/[A-Z]/)||!/[@$%&]/.test(look(stream, -2))&&stream.eat(/[=|\\\-#?@;:&`~\^!\[\]*'"$+.,\/<>()]/)){
712 var c=stream.current();
713 if(PERL[c])
714 return "builtin";}
715 stream.pos=p;}
716 if(/[$@%&]/.test(ch)){
717 if(stream.eatWhile(/[\w$]/)||stream.eat("{")&&stream.eatWhile(/[\w$]/)&&stream.eat("}")){
718 var c=stream.current();
719 if(PERL[c])
720 return "builtin";
721 else
722 return "variable";}}
723 if(ch=="#"){
724 if(look(stream, -2)!="$"){
725 stream.skipToEnd();
726 return "comment";}}
727 if(/[:+\-\^*$&%@=<>!?|\/~\.]/.test(ch)){
728 var p=stream.pos;
729 stream.eatWhile(/[:+\-\^*$&%@=<>!?|\/~\.]/);
730 if(PERL[stream.current()])
731 return "operator";
732 else
733 stream.pos=p;}
734 if(ch=="_"){
735 if(stream.pos==1){
736 if(suffix(stream, 6)=="_END__"){
737 return tokenChain(stream,state,['\0'],"comment");}
738 else if(suffix(stream, 7)=="_DATA__"){
739 return tokenChain(stream,state,['\0'],"builtin");}
740 else if(suffix(stream, 7)=="_C__"){
741 return tokenChain(stream,state,['\0'],"string");}}}
742 if(/\w/.test(ch)){
743 var p=stream.pos;
744 if(look(stream, -2)=="{"&&(look(stream, 0)=="}"||stream.eatWhile(/\w/)&&look(stream, 0)=="}"))
745 return "string";
746 else
747 stream.pos=p;}
748 if(/[A-Z]/.test(ch)){
749 var l=look(stream, -2);
750 var p=stream.pos;
751 stream.eatWhile(/[A-Z_]/);
752 if(/[\da-z]/.test(look(stream, 0))){
753 stream.pos=p;}
754 else{
755 var c=PERL[stream.current()];
756 if(!c)
757 return "meta";
758 if(c[1])
759 c=c[0];
760 if(l!=":"){
761 if(c==1)
762 return "keyword";
763 else if(c==2)
764 return "def";
765 else if(c==3)
766 return "atom";
767 else if(c==4)
768 return "operator";
769 else if(c==5)
770 return "builtin";
771 else
772 return "meta";}
773 else
774 return "meta";}}
775 if(/[a-zA-Z_]/.test(ch)){
776 var l=look(stream, -2);
777 stream.eatWhile(/\w/);
778 var c=PERL[stream.current()];
779 if(!c)
780 return "meta";
781 if(c[1])
782 c=c[0];
783 if(l!=":"){
784 if(c==1)
785 return "keyword";
786 else if(c==2)
787 return "def";
788 else if(c==3)
789 return "atom";
790 else if(c==4)
791 return "operator";
792 else if(c==5)
793 return "builtin";
794 else
795 return "meta";}
796 else
797 return "meta";}
798 return null;}
799
800 export const perl = {
801 name: "perl",
802
803 startState: function() {
804 return {
805 tokenize: tokenPerl,
806 chain: null,
807 style: null,
808 tail: null
809 };
810 },
811 token: function(stream, state) {
812 return (state.tokenize || tokenPerl)(stream, state);
813 },
814 languageData: {
815 commentTokens: {line: "#"},
816 wordChars: "$"
817 }
818 };