parent
3e091b5b9a
commit
72e63eafc4
54
mode/perl.py
54
mode/perl.py
|
@ -13,17 +13,34 @@ class PodGrammar(Grammar):
|
|||
RegionRule(r'entry', r'(?<=^=encoding) +.*$', Grammar, '^\n$'),
|
||||
]
|
||||
|
||||
class StringGrammar(Grammar):
|
||||
def _make_string_rules(forbidden=None):
|
||||
if forbidden:
|
||||
rule = PatternRule(r'scalar', r"\$[^A-Za-z0-9 \\%s](?![A-Za-z0-9_])" % forbidden)
|
||||
else:
|
||||
rule = ContextPatternRule(r'scalar', r"\$[^A-Za-z0-9 %(delim)s](?![A-Za-z0-9_])", r"\$[^A-Za-z0-9 ](?![A-Za-z0-9_])")
|
||||
rules = [
|
||||
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||
PatternRule(r'escaped', r'\\.'),
|
||||
PatternRule(r'deref', r"\$+[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*(?:->{\$?(?:[a-zA-Z_][a-zA-Z_0-9]*|'(?:\\.|[^'\\])*'|\"(\\.|[^\\\"])*\")}|->\[\$?[0-9a-zA-Z_]+\])+"),
|
||||
PatternRule(r'length', r"\$#[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"),
|
||||
ContextPatternRule(r'scalar', r"\$[^A-Za-z0-9 %(delim)s](?![A-Za-z0-9_])", r"\$[^A-Za-z0-9 ](?![A-Za-z0-9_])"),
|
||||
rule,
|
||||
PatternRule(r'scalar', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"),
|
||||
PatternRule(r'cast', r"[\$\@\%\&]{.*?}"),
|
||||
PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"),
|
||||
]
|
||||
return rules
|
||||
|
||||
class StringGrammar(Grammar):
|
||||
rules = _make_string_rules()
|
||||
|
||||
class QuotedGrammar1(Grammar):
|
||||
rules = _make_string_rules(')')
|
||||
class QuotedGrammar2(Grammar):
|
||||
rules = _make_string_rules('}')
|
||||
class QuotedGrammar3(Grammar):
|
||||
rules = _make_string_rules('>')
|
||||
class QuotedGrammar4(Grammar):
|
||||
rules = _make_string_rules(']')
|
||||
|
||||
class PerlGrammar(Grammar):
|
||||
rules = [
|
||||
|
@ -77,13 +94,22 @@ class PerlGrammar(Grammar):
|
|||
PatternRule(r'function', r"&\$*(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"),
|
||||
PatternRule(r'builtin', r"(?<!->)&?(?: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_])"),
|
||||
|
||||
# quote operator
|
||||
RegionRule(r'quoted', r'q[rqwx]? *\(', Grammar, r'\)'),
|
||||
RegionRule(r'quoted', r'q[rqwx]? *{', Grammar, r'}'),
|
||||
RegionRule(r'quoted', r'q[rqwx]? *<', Grammar, r'>'),
|
||||
RegionRule(r'quoted', r'q[rqwx]? *\[', Grammar, r'\]'),
|
||||
RegionRule(r'quoted', r'q[rqwx]? *(?P<delim>[^ #])', Grammar, r'%(delim)s'),
|
||||
RegionRule(r'quoted', r'q[rqwx]?#', Grammar, r'#'),
|
||||
# quote operator: qq(), qx() and qr() usually interpolate
|
||||
RegionRule(r'quoted', r'q[rqx] *(?P<delim>\()', QuotedGrammar1, r'\)'),
|
||||
RegionRule(r'quoted', r'q[rqx] *(?P<delim>{)', QuotedGrammar2, r'}'),
|
||||
RegionRule(r'quoted', r'q[rqx] *(?P<delim><)', QuotedGrammar3, r'>'),
|
||||
RegionRule(r'quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'),
|
||||
RegionRule(r'quoted', r"q[rqx] *(?P<delim>')", Grammar, r"'"),
|
||||
RegionRule(r'quoted', r'q[rqx] *(?P<delim>[^ #])', StringGrammar, r'%(delim)s'),
|
||||
RegionRule(r'quoted', r'q[rqx](?P<delim>#)', StringGrammar, r'#'),
|
||||
|
||||
# quote operator: q() and qw() do not interpolate
|
||||
RegionRule(r'quoted', r'qw? *\(', Grammar, r'\)'),
|
||||
RegionRule(r'quoted', r'qw? *{', Grammar, r'}'),
|
||||
RegionRule(r'quoted', r'qw? *<', Grammar, r'>'),
|
||||
RegionRule(r'quoted', r'qw? *\[', Grammar, r'\]'),
|
||||
RegionRule(r'quoted', r'qw?#', Grammar, r'#'),
|
||||
RegionRule(r'quoted', r'qw? *(?P<delim>[^ #])', Grammar, r'%(delim)s'),
|
||||
|
||||
PatternRule(r'function', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()"),
|
||||
PatternRule(r'class', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"),
|
||||
|
@ -230,10 +256,12 @@ class Perl(mode2.Fundamental):
|
|||
'evalstring.end': ('cyan', 'default'),
|
||||
|
||||
# quoted region
|
||||
'quoted': ('cyan', 'default'),
|
||||
'quoted.start': ('cyan', 'default'),
|
||||
'quoted.null': ('cyan', 'default'),
|
||||
'quoted.end': ('cyan', 'default'),
|
||||
'quoted': ('cyan', 'default'),
|
||||
'quoted.start': ('cyan', 'default'),
|
||||
'quoted.null': ('cyan', 'default'),
|
||||
'quoted.escaped': ('magenta', 'default'),
|
||||
'quoted.deref': ('yellow', 'default'),
|
||||
'quoted.end': ('cyan', 'default'),
|
||||
|
||||
# match regex
|
||||
'match.start': ('cyan', 'default'),
|
||||
|
|
Loading…
Reference in New Issue