diff --git a/mode/perl.py b/mode/perl.py index fb73c28..744ad90 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -49,14 +49,16 @@ def _make_string_rules(forbidden): rules = [ PatternRule('octal', r'\\[0-7]{3}'), PatternRule('escaped', r'\\.'), - PatternRule('deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + + PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + hword + "|" + strg1 + "|" + strg2 + ")}|" + "(?:->)?\[\$?"+hword+"\]"+ ")+"), - PatternRule('length', r"\$#" + word2), - PatternRule('scalar', r"\$\$*" + word2), - PatternRule('scalar', r"\$[0-9]+"), - PatternRule('cast', r"[\$\@\%\&]{.+?}"), - PatternRule('array', r"@\$*" + word2), + PatternRule('perl.length', r"\$#" + word2), + PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'), + PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'), + PatternRule('perl.scalar', r"\$\$*" + word2), + PatternRule('perl.scalar', r"\$[0-9]+"), + PatternRule('perl.array', r"@\$*" + word2), + PatternRule('perl.hash', r"\%\$*" + word2), ] if forbidden == ')': rules.append(PatternRule('data', r"\([^$%@\(\)]*\)")) @@ -136,17 +138,21 @@ class PerlGrammar(Grammar): RegionRule('perl.string', '"', StringGrammar, '"'), RegionRule('perl.string', "'", StrictStringGrammar, "'"), RegionRule('perl.evalstring', "`", EvalGrammar, "`"), - PatternRule('perl.keyword', "(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|no|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), - PatternRule('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'), + PatternRule('perl.keyword', "(?)(?:continue|do|else|elsif|eval|foreach|for|if|last|my|next|no|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), + PatternRule('perl.builtin', "(?)(?:STDIN|STDERR|STDOUT)(?![a-zA-Z0-9_])"), + PatternRule('perl.hashkey', '(?<={)' + wchr2 + '+(?=})'), PatternRule('perl.method', '(?<=->)' + word1), - PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'), + PatternRule('perl.hashkey', wchr2 + '+(?= *=>)'), PatternRule('perl.length', r"\$#" + word2), - PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), + #PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), PatternRule('perl.number', r'0[xX][0-9A-Fa-f]+'), PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), # built-in scalars + PatternRule('perl.array', r'\$' + word2 + '(?= *\[)'), + PatternRule('perl.hash', r'\$' + word2 + '(?= *\{)'), + PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'), PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'), PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'), @@ -158,12 +164,14 @@ class PerlGrammar(Grammar): PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + wchr2 + ")"), - PatternRule('perl.array', "@_"), + PatternRule('perl.array', r"\@_"), PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), PatternRule('perl.scalar', r"\$[0-9]+"), PatternRule('perl.scalar', r"\$\$*" + word2), - PatternRule('perl.array', r"@\$*" + word2), - PatternRule('perl.hash', r"%\$*" + word2), + PatternRule('perl.array', r"\@(?= *{)"), + PatternRule('perl.array', r"\@\$*" + word2), + PatternRule('perl.hash', r"\%(?= *{)"), + PatternRule('perl.hash', r"\%\$*" + word2), # match regexes; paired delimiters RegionRule('perl.match', r'm *(?P\()', @@ -217,6 +225,7 @@ class PerlGrammar(Grammar): PatternRule('perl.use', "(?<=no )" + word2), PatternRule('perl.require', "(?<=require )" + word2), PatternRule('perl.label', word1 + ':(?!:)'), + PatternRule('perl.function', r'&(?= *{)'), PatternRule('perl.function', r"&\$*" + word2), PatternRule('perl.builtin', "(?)&?(?:write|warn|wantarray|waitpid|wait|vec|values|utime|use|untie|unshift|unpack|unlink|undef|umask|ucfirst|uc|truncate|times|time|tied|tie|telldir|tell|syswrite|system|sysseek|sysread|sysopen|syscall|symlink|substr|sub|study|stat|srand|sqrt|sprintf|split|splice|sort|socketpair|socket|sleep|sin|shutdown|shmwrite|shmread|shmget|shmctl|shift|setsockopt|setservent|setpwent|setprotoent|setpriority|setpgrp|setnetent|sethostent|setgrent|send|semop|semget|semctl|select|seekdir|seek|scalar|rmdir|rindex|rewinddir|reverse|return|reset|require|rename|ref|redo|recv|readpipe|readlink|readline|readdir|read|rand|quotemeta|push|prototype|printf|print|pos|pop|pipe|package|pack|our|ord|opendir|open|oct|no|next|my|msgsnd|msgrcv|msgget|msgctl|mkdir|map|lstat|log|lock|localtime|local|listen|link|length|lcfirst|lc|last|kill|keys|join|ioctl|int|index|import|hex|grep|goto|gmtime|glob|getsockopt|getsockname|getservent|getservbyport|getservbyname|getpwuid|getpwnam|getpwent|getprotoent|getprotobynumber|getprotobyname|getpriority|getppid|getpgrp|getpeername|getnetent|getnetbyname|getnetbyaddr|getlogin|gethostent|gethostbyname|gethostbyaddr|getgrnam|getgrgid|getgrent|getc|formline|format|fork|flock|fileno|fcntl|exp|exit|exists|exec|eval|eof|endservent|endpwent|endprotoent|endnetent|endhostent|endgrent|each|dump|do|die|delete|defined|dbmopen|dbmclose|crypt|cos|continue|connect|closedir|close|chroot|chr|chown|chop|chomp|chmod|chdir|caller|bless|binmode|bind|atan2|alarm|accept|abs)(?![a-zA-Z0-9_])"), @@ -240,6 +249,7 @@ class PerlGrammar(Grammar): PatternRule('perl.function', word2 + r"(?= *\()"), PatternRule('perl.class', word2 + "(?=->)"), + PatternRule('perl.glob', r'\*(?= *{)'), PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2), # some basic stuff @@ -272,7 +282,7 @@ class PerlTabber(StackTabber2): end_free_tokens = {'perl.string.end': 1, 'perl.pod.end': 1, 'perl.heredoc.end': 1, - 'perl.evaldoc.start': 1} + 'perl.evaldoc.end': 1} class PerlSetLib(Method): '''Set the path(s) to find perl modules''' @@ -718,6 +728,32 @@ class PerlContext(context.Context): if curr: self.namelines[i] = (curr, tuple(stack)) i += 1 +# green is for strings and hash keys +low_green = ('green130', 'default', 'bold') +lit_green = ('green251', 'default', 'bold') + +# cyan is for quotes, evals, regexes, subs +low_cyan = ('cyan022', 'default', 'bold') +med_cyan = ('cyan', 'default', 'bold') +lit_cyan = ('cyan255', 'default', 'bold') + +# magenta is for keywords/builtins, translation, globs +low_magenta = ('magenta424', 'default', 'bold') +med_magenta = ('magenta', 'default', 'bold') +lit_magenta = ('magenta515', 'default', 'bold') + +# yellow is for variables +med_yellow = ('yellow', 'default', 'bold') +lit_orange = ('yellow530', 'default', 'bold') +med_orange = ('yellow520', 'default', 'bold') + +# red is for comments, pods, endblocks +low_red = ('red300', 'default', 'bold') +med_red = ('red', 'default', 'bold') +lit_red = ('red500', 'default', 'bold') + +# blue is unused + class Perl(Fundamental): name = 'Perl' extensions = ['.pl', '.pm', '.pod', '.t'] @@ -731,103 +767,103 @@ class Perl(Fundamental): closetags = {')': '(', ']': '[', '}': '{'} colors = { # comments - 'endblock.start': ('red', 'default', 'bold'), - 'endblock.data': ('red', 'default', 'bold'), - 'endblock.null': ('red', 'default', 'bold'), - 'endblock.end': ('red', 'default', 'bold'), + 'endblock.start': low_red, + 'endblock.end': lit_red, + 'endblock.data': lit_red, + 'endblock.null': lit_red, # pod - 'pod.start': ('red', 'default', 'bold'), - 'pod.null': ('red', 'default', 'bold'), - 'pod.entry.start': ('magenta', 'default', 'bold'), - 'pod.entry.data': ('magenta', 'default', 'bold'), - 'pod.entry.null': ('magenta', 'default', 'bold'), - 'pod.entry.end': ('magenta', 'default', 'bold'), - 'pod.end': ('red', 'default', 'bold'), + 'pod.start': med_red, + 'pod.end': med_red, + 'pod.data': med_red, + 'pod.null': med_red, + 'pod.entry.start': med_magenta, + 'pod.entry.end': med_magenta, + 'pod.entry.data': med_magenta, + 'pod.entry.null': med_magenta, # basic stuff - 'null': ('default', 'default', 'bold'), - 'sub': ('cyan', 'default', 'bold'), - 'prototype': ('yellow', 'default', 'bold'), - 'noperator': ('magenta', 'default', 'bold'), - 'endblock': ('red', 'default', 'bold'), - 'perl.keyword': ('magenta', 'default', 'bold'), - 'cast': ('yellow', 'default', 'bold'), - 'scalar': ('yellow', 'default', 'bold'), - 'length': ('yellow', 'default', 'bold'), - 'array': ('yellow', 'default', 'bold'), - 'deref': ('yellow', 'default', 'bold'), - 'perl.hash': ('yellow', 'default', 'bold'), - 'hash_key': ('green', 'default', 'bold'), - 'perl.method': ('cyan', 'default', 'bold'), - 'perl.function': ('cyan', 'default', 'bold'), - 'perl.builtin': ('magenta', 'default', 'bold'), - 'perl.label': ('cyan', 'default', 'bold'), - 'package': ('cyan', 'default', 'bold'), - 'perl.class': ('cyan', 'default', 'bold'), - 'use': ('cyan', 'default', 'bold'), - 'require': ('cyan', 'default', 'bold'), + 'perl.sub': med_cyan, + 'prototype': med_yellow, + 'noperator': med_magenta, + 'perl.keyword': low_magenta, + 'perl.builtin': med_magenta, + #'perl.cast': med_yellow, + 'perl.scalar': med_yellow, + 'perl.length': med_yellow, + 'perl.deref': med_yellow, + 'perl.array': lit_orange, + 'perl.hash': med_orange, + 'perl.hashkey': lit_green, + 'perl.method': med_cyan, + 'perl.function': med_cyan, + 'perl.builtin': med_magenta, + 'perl.label': med_cyan, + 'package': med_cyan, + 'perl.class': med_cyan, + 'perl.use': med_cyan, + 'perl.require': med_cyan, # heredoc/evaldoc - 'heredoc.start': ('green', 'default', 'bold'), - 'heredoc.data': ('green', 'default', 'bold'), - 'heredoc.null': ('green', 'default', 'bold'), - 'heredoc.end': ('green', 'default', 'bold'), - 'evaldoc.start': ('cyan', 'default', 'bold'), - 'evaldoc.null': ('cyan', 'default', 'bold'), - 'evaldoc.end': ('cyan', 'default', 'bold'), + 'heredoc.start': low_green, + 'heredoc.end': low_green, + 'heredoc.data': lit_green, + 'heredoc.null': lit_green, + + 'evaldoc.start': low_cyan, + 'evaldoc.end': low_cyan, + 'evaldoc.data': lit_cyan, + 'evaldoc.null': lit_cyan, # strings - 'perl.string.start': ('green', 'default', 'bold'), - 'perl.string.null': ('green', 'default', 'bold'), - 'perl.string.escaped': ('magenta', 'default', 'bold'), - 'perl.string.deref': ('yellow', 'default', 'bold'), - 'perl.string.end': ('green', 'default', 'bold'), + 'perl.string.start': low_green, + 'perl.string.end': low_green, + 'perl.string.data': lit_green, + 'perl.string.null': lit_green, + 'perl.string.escaped': med_magenta, + 'perl.string.deref': med_yellow, # `` strings - 'evalstring.start': ('cyan', 'default', 'bold'), - 'evalstring.null': ('cyan', 'default', 'bold'), - 'evalstring.escaped': ('magenta', 'default', 'bold'), - 'evalstring.deref': ('yellow', 'default', 'bold'), - 'evalstring.end': ('cyan', 'default', 'bold'), + 'evalstring.start': low_cyan, + 'evalstring.end': low_cyan, + 'evalstring.data': lit_cyan, + 'evalstring.null': lit_cyan, + 'evalstring.escaped': med_magenta, + 'evalstring.deref': med_yellow, # quoted region - 'perl.quoted': ('cyan', 'default', 'bold'), - 'perl.quoted.start': ('cyan', 'default', 'bold'), - 'perl.quoted.null': ('cyan', 'default', 'bold'), - 'perl.quoted.data': ('cyan', 'default', 'bold'), - 'perl.quoted.escaped': ('magenta', 'default', 'bold'), - 'perl.quoted.deref': ('yellow', 'default', 'bold'), - 'perl.quoted.end': ('cyan', 'default', 'bold'), + 'perl.quoted.start': low_cyan, + 'perl.quoted.end': low_cyan, + 'perl.quoted.data': lit_cyan, + 'perl.quoted.null': lit_cyan, + 'perl.quoted.escaped': med_magenta, + 'perl.quoted.deref': med_yellow, # match regex - 'match.start': ('cyan', 'default', 'bold'), - 'match.end': ('cyan', 'default', 'bold'), - 'match.data': ('cyan', 'default', 'bold'), - 'match.null': ('cyan', 'default', 'bold'), + 'match.start': low_cyan, + 'match.end': low_cyan, + 'match.data': lit_cyan, + 'match.null': lit_cyan, # replace regex - 'replace.start': ('cyan', 'default', 'bold'), - 'replace.middle0': ('cyan', 'default', 'bold'), - 'replace.middle1': ('cyan', 'default', 'bold'), - 'replace.end': ('cyan', 'default', 'bold'), - 'replace.data': ('cyan', 'default', 'bold'), - 'replace.null': ('cyan', 'default', 'bold'), - 'replace.escaped': ('magenta', 'default', 'bold'), - 'replace.deref': ('yellow', 'default', 'bold'), - 'replace.length': ('yellow', 'default', 'bold'), - 'replace.scalar': ('yellow', 'default', 'bold'), - 'replace.perl.hash': ('yellow', 'default', 'bold'), - 'replace.cast': ('yellow', 'default', 'bold'), + 'replace.start': low_cyan, + 'replace.middle0': low_cyan, + 'replace.middle1': low_cyan, + 'replace.end': low_cyan, + 'replace.data': lit_cyan, + 'replace.null': lit_cyan, + 'replace.escaped': med_magenta, + 'replace.deref': med_yellow, # translate regex - 'translate.start': ('magenta', 'default', 'bold'), - 'translate.middle0': ('magenta', 'default', 'bold'), - 'translate.end': ('magenta', 'default', 'bold'), - 'translate.null': ('magenta', 'default', 'bold'), + 'translate.start': low_magenta, + 'translate.middle0': low_magenta, + 'translate.end': low_magenta, + 'translate.data': lit_magenta, + 'translate.null': lit_magenta, # xyz - 'perl.glob': ('magenta', 'default', 'bold'), + 'perl.glob': med_magenta, } config = {} lconfig = {'perl.libs': []}