improved perl grammar and some clean up

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-07-26 22:50:12 -04:00
parent e3b2818038
commit 34f81cdb0d
2 changed files with 205 additions and 200 deletions

View File

@ -213,14 +213,13 @@ class Application(object):
curses.def_prog_mode() curses.def_prog_mode()
def _load_config_defaults(self): def _load_config_defaults(self):
self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg'] self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg']
self.config['error_timeout'] = -1 self.config['error_timeout'] = -1
self.config['max_error_len'] = 192 self.config['max_error_len'] = 192
self.config['max_num_kills'] = 64 self.config['max_num_kills'] = 64
self.config['word_letters'] = string.ascii_letters + string.digits self.config['word_letters'] = string.ascii_letters + string.digits
self.config['default_color'] = ('default', 'default',) self.config['default_color'] = ('default', 'default',)
self.config['margin'] = 80 self.config['margin'] = 79
self.config['margin_color'] = 'blue' self.config['margin_color'] = 'blue'
self.config['use_last_replace'] = False self.config['use_last_replace'] = False

View File

@ -16,6 +16,8 @@ from tab import StackTabber, StackTabber2
from parse import Any, And, Or, Optional, Name, Match, Matchs from parse import Any, And, Or, Optional, Name, Match, Matchs
import term import term
class PerlGrammar(Grammar): pass
class WhitespaceGrammar(Grammar): class WhitespaceGrammar(Grammar):
rules = [ rules = [
PatternRule('spaces', ' +'), PatternRule('spaces', ' +'),
@ -49,16 +51,21 @@ def _make_string_rules(forbidden):
rules = [ rules = [
PatternRule('octal', r'\\[0-7]{3}'), PatternRule('octal', r'\\[0-7]{3}'),
PatternRule('escaped', r'\\.'), PatternRule('escaped', r'\\.'),
PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + #PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
hword + "|" + strg1 + "|" + strg2 + ")}|" + # hword + "|" + strg1 + "|" + strg2 + ")}|" +
"(?:->)?\[\$?"+hword+"\]"+ ")+"), # "(?:->)?\[\$?"+hword+"\]"+ ")+"),
PatternRule('perl.length', r"\$#" + word2), PatternRule('perl.length', r"\$#" + word2),
PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'), PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'),
PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'), PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'),
PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule('perl.scalar', r"\$[0-9]+"), PatternRule('perl.scalar', r"\$[0-9]+"),
PatternRule('perl.array', r"@\$*" + word2), PatternRule('perl.array', r"@\$*" + word2),
PatternRule('perl.hash', r"\%\$*" + word2), PatternRule('perl.hash', r"\%\$*" + word2),
PatternMatchRule('x', r"(\$\$*" + word2 + ')(->)', 'perl.scalar', 'delimiter'),
PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule('perl.scalar', r"\$\$*" + word2),
#RegionRule('perl.interpolate', r'\[', PerlGrammar, r'\]'),
#RegionRule('perl.interpolate', '{', PerlGrammar, '}'),
] ]
if forbidden == ')': if forbidden == ')':
rules.append(PatternRule('data', r"\([^$%@\(\)]*\)")) rules.append(PatternRule('data', r"\([^$%@\(\)]*\)"))
@ -87,7 +94,7 @@ class StrictStringGrammar(Grammar): rules = [
PatternRule('data', r"[^\\']+"), PatternRule('data', r"[^\\']+"),
] ]
class StringGrammar(Grammar): class StringGrammar(Grammar):
rules = _make_string_rules('"') + [PatternRule('data', r'[^$%@\\"]+')] rules = _make_string_rules('"') #+ [PatternRule('data', r'[^$%@\\"]+')]
class EvalGrammar(Grammar): class EvalGrammar(Grammar):
rules = _make_string_rules('`') + [PatternRule('data', r'[^$%@\\`]+')] rules = _make_string_rules('`') + [PatternRule('data', r'[^$%@\\`]+')]
@ -111,159 +118,158 @@ class QuotedGrammar2(Grammar): rules = _make_string_rules('}')
class QuotedGrammar3(Grammar): rules = _make_string_rules('>') class QuotedGrammar3(Grammar): rules = _make_string_rules('>')
class QuotedGrammar4(Grammar): rules = _make_string_rules(']') class QuotedGrammar4(Grammar): rules = _make_string_rules(']')
class PerlGrammar(Grammar): PerlGrammar.rules = [
rules = [ RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None,
RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None, r';\n', StringGrammar, r'^%(heredoc)s$'),
r';\n', StringGrammar, r'^%(heredoc)s$'), RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None,
RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None, r';\n', StringGrammar, r'^%(heredoc)s$'),
r';\n', StringGrammar, r'^%(heredoc)s$'), RegionRule('perl.heredoc', r"<< *'(?P<heredoc>[^']+)'", None,
RegionRule('perl.heredoc', r"<< *'(?P<heredoc>[^']+)'", None, r";\n", DataGrammar, r'^%(heredoc)s$'),
r";\n", DataGrammar, r'^%(heredoc)s$'), RegionRule('perl.evaldoc', r"<< *`(?P<heredoc>[^`]+)`", None,
RegionRule('perl.evaldoc', r"<< *`(?P<heredoc>[^`]+)`", None, r";\n", StringGrammar, r'^%(heredoc)s$'),
r";\n", StringGrammar, r'^%(heredoc)s$'),
RegionRule('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''), RegionRule('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''),
RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'), RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'),
OverridePatternRule('perl.comment', '#@@:(?P<token>' + pname + OverridePatternRule('perl.comment', '#@@:(?P<token>' + pname +
'):(?P<mode>' + pname + ') *$'), '):(?P<mode>' + pname + ') *$'),
PatternMatchRule('x', '(sub)( +)(' + word2 + PatternMatchRule('x', '(sub)( +)(' + word2 +
r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))',
'perl.keyword', 'spaces', 'perl.sub', 'spaces', 'perl.keyword', 'spaces', 'perl.sub', 'spaces',
'delimiter', 'spaces', 'perl.prototype', 'delimiter', 'spaces', 'perl.prototype',
'spaces', 'delimiter'), 'spaces', 'delimiter'),
PatternRule('perl.comment', '#.*$'), PatternRule('perl.comment', '#.*$'),
RegionRule('perl.string', '"', StringGrammar, '"'), RegionRule('perl.string', '"', StringGrammar, '"'),
RegionRule('perl.string', "'", StrictStringGrammar, "'"), RegionRule('perl.string', "'", StrictStringGrammar, "'"),
RegionRule('perl.evalstring', "`", EvalGrammar, "`"), RegionRule('perl.evalstring', "`", EvalGrammar, "`"),
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.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.reserved', "(?<!->)(?:STDIN|STDERR|STDOUT|__PACKAGE__)(?![a-zA-Z0-9_])"), PatternRule('perl.reserved', "(?<!->)(?:STDIN|STDERR|STDOUT|__PACKAGE__)(?![a-zA-Z0-9_])"),
PatternRule('perl.hashkey', '(?<={)' + wchr2 + '+(?=})'), PatternRule('perl.hashkey', '(?<={)' + wchr2 + '+(?=})'),
PatternRule('perl.method', '(?<=->)' + word1), PatternRule('perl.method', '(?<=->)' + word1),
PatternRule('perl.hashkey', wchr2 + '+(?= *=>)'), PatternRule('perl.hashkey', wchr2 + '+(?= *=>)'),
PatternRule('perl.length', r"\$#" + word2), 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[xX][0-9A-Fa-f]+'),
PatternRule('perl.number', r'-?0?\.[0-9]+|-?[0-9]+(?:\.[0-9]+)?'), PatternRule('perl.number', r'-?0?\.[0-9]+|-?[0-9]+(?:\.[0-9]+)?'),
# built-in scalars # built-in scalars
PatternRule('perl.array', r'\$' + word2 + '(?= *\[)'), PatternRule('perl.array', r'\$' + word2 + '(?= *\[)'),
PatternRule('perl.hash', r'\$' + word2 + '(?= *\{)'), PatternRule('perl.hash', r'\$' + word2 + '(?= *\{)'),
PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'), PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'),
PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'), PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'),
PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'), PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'),
PatternRule('perl.scalar', r'\$\^O'), PatternRule('perl.scalar', r'\$\^O'),
PatternRule('perl.scalar', r'\${\^' + word1 + '}'), PatternRule('perl.scalar', r'\${\^' + word1 + '}'),
PatternRule('perl.array', r'\@[\+\-]'), PatternRule('perl.array', r'\@[\+\-]'),
PatternRule('perl.hash', r'\%(?:[!]|^H)'), PatternRule('perl.hash', r'\%(?:[!]|^H)'),
PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" +
wchr2 + ")"), wchr2 + ")"),
PatternRule('perl.array', r"\@_"), PatternRule('perl.array', r"\@_"),
PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"),
PatternRule('perl.scalar', r"\$[0-9]+"), PatternRule('perl.scalar', r"\$[0-9]+"),
PatternRule('perl.scalar', r"\$\$*" + word2), PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule('perl.array', r"\@(?= *{)"), PatternRule('perl.array', r"\@(?= *{)"),
PatternRule('perl.array', r"\@\$*" + word2), PatternRule('perl.array', r"\@\$*" + word2),
PatternRule('perl.hash', r"\%(?= *{)"), PatternRule('perl.hash', r"\%(?= *{)"),
PatternRule('perl.hash', r"\%\$*" + word2), PatternRule('perl.hash', r"\%\$*" + word2),
# match regexes; paired delimiters # match regexes; paired delimiters
RegionRule('perl.match', r'm *(?P<delim>\()', RegionRule('perl.match', r'm *(?P<delim>\()',
MatchGrammar3, r'\)[a-z]*'), MatchGrammar3, r'\)[a-z]*'),
RegionRule('perl.match', r'm *(?P<delim>\[)', RegionRule('perl.match', r'm *(?P<delim>\[)',
MatchGrammar4, r'\][a-z]*'), MatchGrammar4, r'\][a-z]*'),
RegionRule('perl.match', r'm *(?P<delim>\{)', RegionRule('perl.match', r'm *(?P<delim>\{)',
MatchGrammar5, r'\}[a-z]*'), MatchGrammar5, r'\}[a-z]*'),
RegionRule('perl.match', r'm *(?P<delim>\<)', RegionRule('perl.match', r'm *(?P<delim>\<)',
MatchGrammar6, r'\>[a-z]*'), MatchGrammar6, r'\>[a-z]*'),
# match regexes; standard delimiters # match regexes; standard delimiters
RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)|(?<=&&)|(?<==)) *(?P<delim>/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)|(?<=&&)|(?<==)) *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.match', 'm *(?P<delim>/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', 'm *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.match', 'm *(?P<delim>[^ #a-zA-Z0-9_])', RegionRule('perl.match', 'm *(?P<delim>[^ #a-zA-Z0-9_])',
MatchGrammar0, '%(delim)s[a-z]*'), MatchGrammar0, '%(delim)s[a-z]*'),
RegionRule('perl.match', 'm(?P<delim>#)', MatchGrammar2, '#[a-z]*'), RegionRule('perl.match', 'm(?P<delim>#)', MatchGrammar2, '#[a-z]*'),
# replace regexes; paired delimiters # replace regexes; paired delimiters
RegionRule('perl.replace', r's *(?P<delim>\()', MatchGrammar3, RegionRule('perl.replace', r's *(?P<delim>\()', MatchGrammar3,
r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'), r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\[)', MatchGrammar4, RegionRule('perl.replace', r's *(?P<delim>\[)', MatchGrammar4,
r'\]', WhitespaceGrammar, '\[', MatchGrammar4, r'\][a-z]*'), r'\]', WhitespaceGrammar, '\[', MatchGrammar4, r'\][a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\{)', MatchGrammar5, RegionRule('perl.replace', r's *(?P<delim>\{)', MatchGrammar5,
r'\}', WhitespaceGrammar, '\{', MatchGrammar5, r'\}[a-z]*'), r'\}', WhitespaceGrammar, '\{', MatchGrammar5, r'\}[a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\<)', MatchGrammar6, RegionRule('perl.replace', r's *(?P<delim>\<)', MatchGrammar6,
r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'), r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'),
# replace regexes; standard delimiters # replace regexes; standard delimiters
RegionRule('perl.replace', 's *(?P<delim>/)', MatchGrammar1, RegionRule('perl.replace', 's(?P<delim>#)',
'/', MatchGrammar1, '/[a-z]*'), MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])', RegionRule('perl.replace', 's *(?P<delim>/)',
MatchGrammar0, '%(delim)s', MatchGrammar1, '/', MatchGrammar1, '/[a-z]*'),
MatchGrammar0, '%(delim)s[a-z]*'), RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
RegionRule('perl.replace', 's(?P<delim>#)', MatchGrammar0, '%(delim)s',
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'), MatchGrammar0, '%(delim)s[a-z]*'),
# translate operator # translate operator
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)', RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)',
TranslateGrammar1, '/', TranslateGrammar1, '/[a-z]*'), TranslateGrammar1, '/', TranslateGrammar1, '/[a-z]*'),
RegionRule('perl.translate', '(?:y|tr)#', TranslateGrammar2, RegionRule('perl.translate', '(?:y|tr)#', TranslateGrammar2,
'#', TranslateGrammar2, '#[a-z]*'), '#', TranslateGrammar2, '#[a-z]*'),
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>[^ a-zA-Z0-9_])', RegionRule('perl.translate', '(?:y|tr) *(?P<delim>[^ a-zA-Z0-9_])',
TranslateGrammarX, '%(delim)s', TranslateGrammarX, TranslateGrammarX, '%(delim)s', TranslateGrammarX,
'%(delim)s[a-z]*'), '%(delim)s[a-z]*'),
# some more basic stuff # some more basic stuff
PatternRule('perl.package', "(?<=package )" + word2), PatternRule('perl.package', "(?<=package )" + word2),
PatternRule('perl.sub', "(?<=sub )" + word2), PatternRule('perl.sub', "(?<=sub )" + word2),
PatternRule('perl.use', "(?<=use )" + word2), PatternRule('perl.use', "(?<=use )" + word2),
PatternRule('perl.use', "(?<=no )" + word2), PatternRule('perl.use', "(?<=no )" + word2),
PatternRule('perl.require', "(?<=require )" + word2), PatternRule('perl.require', "(?<=require )" + word2),
PatternRule('perl.label', word1 + ':(?!:)'), PatternRule('perl.label', word1 + ':(?!:)'),
PatternRule('perl.function', r'&(?= *{)'), PatternRule('perl.function', r'&(?= *{)'),
PatternRule('perl.function', r"&\$*" + word2), 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_])"), 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_])"),
# quote operator: qq(), qx() and qr() usually interpolate # quote operator: qq(), qx() and qr() usually interpolate
RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\()', QuotedGrammar1, r'\)'), RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\()', QuotedGrammar1, r'\)'),
RegionRule('perl.quoted', 'q[rqx] *(?P<delim>{)', QuotedGrammar2, '}'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim>{)', QuotedGrammar2, '}'),
RegionRule('perl.quoted', 'q[rqx] *(?P<delim><)', QuotedGrammar3, '>'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim><)', QuotedGrammar3, '>'),
RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'), RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'),
RegionRule('perl.quoted', "q[rqx] *(?P<delim>')", Grammar, "'"), RegionRule('perl.quoted', "q[rqx] *(?P<delim>')", Grammar, "'"),
RegionRule('perl.quoted', 'q[rqx](?P<delim>#)', MatchGrammar0, '#'), RegionRule('perl.quoted', 'q[rqx](?P<delim>#)', MatchGrammar0, '#'),
RegionRule('perl.quoted', 'q[rqx] *(?P<delim>[^ a-zA-Z0-9#])', MatchGrammar0, '%(delim)s'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim>[^ a-zA-Z0-9#])', MatchGrammar0, '%(delim)s'),
# quote operator: q() and qw() do not interpolate # quote operator: q() and qw() do not interpolate
RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'), RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'),
RegionRule('perl.quoted', 'qw? *{', NoBrace, '}'), RegionRule('perl.quoted', 'qw? *{', NoBrace, '}'),
RegionRule('perl.quoted', 'qw? *<', NoAngle, '>'), RegionRule('perl.quoted', 'qw? *<', NoAngle, '>'),
RegionRule('perl.quoted', r'qw? *\[', NoBracket, r'\]'), RegionRule('perl.quoted', r'qw? *\[', NoBracket, r'\]'),
RegionRule('perl.quoted', 'qw?#', NoHash, '#'), RegionRule('perl.quoted', 'qw?#', NoHash, '#'),
RegionRule('perl.quoted', 'qw? *(?P<delim>[^ a-zA-Z0-9#])', Grammar, '%(delim)s'), RegionRule('perl.quoted', 'qw? *(?P<delim>[^ a-zA-Z0-9#])', Grammar, '%(delim)s'),
PatternRule('perl.function', word2 + r"(?= *\()"), PatternRule('perl.function', word2 + r"(?= *\()"),
PatternRule('perl.class', word2 + "(?=->)"), PatternRule('perl.class', word2 + "(?=->)"),
PatternRule('perl.glob', r'\*(?= *{)'), PatternRule('perl.glob', r'\*(?= *{)'),
PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2), PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2),
# some basic stuff # some basic stuff
PatternRule('delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"), PatternRule('delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
PatternRule('perl.noperator', "-[rwxoRWXOezsfdlpSbctugkTBMAC](?!" + PatternRule('perl.noperator', "-[rwxoRWXOezsfdlpSbctugkTBMAC](?!" +
wchr2 + ")"), wchr2 + ")"),
PatternRule('perl.operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"), PatternRule('perl.operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"),
PatternRule('perl.operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.\.|\.|x(?![a-zA-Z_])"), PatternRule('perl.operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.\.|\.|x(?![a-zA-Z_])"),
PatternRule('perl.noperator', "(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), PatternRule('perl.noperator', "(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"),
PatternRule('perl.bareword', word2), PatternRule('perl.bareword', word2),
PatternRule('spaces', ' +'), PatternRule('spaces', ' +'),
PatternRule('eol', r"\n$"), PatternRule('eol', r"\n$"),
] ]
class PerlTabber(StackTabber2): class PerlTabber(StackTabber2):
is_ignored_tokens = ('spaces', 'eol', 'perl.comment') is_ignored_tokens = ('spaces', 'eol', 'perl.comment')
@ -731,6 +737,22 @@ class PerlContext(context.Context):
# white is for delimiters, operators, numbers # white is for delimiters, operators, numbers
default = ('default', 'default', 'bold') default = ('default', 'default', 'bold')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default', 'bold')
hi_magenta = ('magenta505', 'default', 'bold')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default', 'bold')
hi_red = ('red511', 'default', 'bold')
# orange are for arrays and hashes
hi_orange = ('yellow531', 'default', 'bold')
lo_orange = ('yellow520', 'default', 'bold')
# yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default', 'bold')
lo_yellow = ('yellow330', 'default', 'bold')
# green is for strings and hash keys # green is for strings and hash keys
lo_green = ('green020', 'default', 'bold') lo_green = ('green020', 'default', 'bold')
hi_green = ('green050', 'default', 'bold') hi_green = ('green050', 'default', 'bold')
@ -739,19 +761,6 @@ hi_green = ('green050', 'default', 'bold')
lo_cyan = ('cyan022', 'default', 'bold') lo_cyan = ('cyan022', 'default', 'bold')
hi_cyan = ('cyan255', 'default', 'bold') hi_cyan = ('cyan255', 'default', 'bold')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default', 'bold')
hi_magenta = ('magenta505', 'default', 'bold')
# yellow/orange are for scalars, arrays and hashes
hi_yellow = ('yellow', 'default', 'bold')
lo_yellow = ('yellow530', 'default', 'bold')
lo_orange = ('yellow520', 'default', 'bold')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default', 'bold')
hi_red = ('red500', 'default', 'bold')
# blue is unused # blue is unused
lo_blue = ('blue113', 'default', 'bold') lo_blue = ('blue113', 'default', 'bold')
hi_blue = ('blue225', 'default', 'bold') hi_blue = ('blue225', 'default', 'bold')
@ -769,11 +778,7 @@ class Perl(Fundamental):
closetags = {')': '(', ']': '[', '}': '{'} closetags = {')': '(', ']': '[', '}': '{'}
colors = { colors = {
# comments # comments
'perl.comment': hi_red, 'perl.comment': hi_red,
'endblock.start': lo_red,
'endblock.end': hi_red,
'endblock.data': hi_red,
'endblock.null': hi_red,
# pod # pod
'pod.start': hi_red, 'pod.start': hi_red,
@ -786,18 +791,19 @@ class Perl(Fundamental):
'pod.entry.null': hi_magenta, 'pod.entry.null': hi_magenta,
# basic stuff # basic stuff
'perl.sub': hi_cyan, 'perl.glob': hi_magenta,
'perl.prototype': hi_yellow,
'perl.noperator': hi_magenta, 'perl.noperator': hi_magenta,
'perl.keyword': hi_magenta, 'perl.keyword': hi_magenta,
'perl.builtin': hi_magenta, 'perl.builtin': hi_magenta,
'perl.reserved': hi_magenta, 'perl.reserved': hi_magenta,
'perl.prototype': hi_yellow,
'perl.scalar': hi_yellow, 'perl.scalar': hi_yellow,
'perl.length': hi_yellow, 'perl.length': hi_yellow,
'perl.deref': hi_yellow, #'perl.deref': hi_yellow,
'perl.array': lo_yellow, 'perl.array': hi_orange,
'perl.hash': lo_orange, 'perl.hash': lo_orange,
'perl.hashkey': hi_green, 'perl.hashkey': hi_green,
'perl.sub': hi_cyan,
'perl.method': hi_cyan, 'perl.method': hi_cyan,
'perl.function': hi_cyan, 'perl.function': hi_cyan,
'perl.label': hi_cyan, 'perl.label': hi_cyan,
@ -805,14 +811,20 @@ class Perl(Fundamental):
'perl.class': hi_cyan, 'perl.class': hi_cyan,
'perl.use': hi_cyan, 'perl.use': hi_cyan,
'perl.require': hi_cyan, 'perl.require': hi_cyan,
'perl.glob': hi_magenta,
# heredoc/evaldoc # end/data block
'endblock.start': hi_red,
'endblock.end': hi_red,
'endblock.data': hi_red,
'endblock.null': hi_red,
# heredoc
'heredoc.start': lo_green, 'heredoc.start': lo_green,
'heredoc.end': lo_green, 'heredoc.end': lo_green,
'heredoc.data': hi_green, 'heredoc.data': hi_green,
'heredoc.null': hi_green, 'heredoc.null': hi_green,
# evaldoc
'evaldoc.start': lo_cyan, 'evaldoc.start': lo_cyan,
'evaldoc.end': lo_cyan, 'evaldoc.end': lo_cyan,
'evaldoc.data': hi_cyan, 'evaldoc.data': hi_cyan,
@ -822,28 +834,22 @@ class Perl(Fundamental):
'perl.number': default, 'perl.number': default,
# strings # strings
'perl.string.start': lo_green, 'perl.string.start': lo_green,
'perl.string.end': lo_green, 'perl.string.end': lo_green,
'perl.string.data': hi_green, 'perl.string.data': hi_green,
'perl.string.null': hi_green, 'perl.string.null': hi_green,
'perl.string.escaped': hi_magenta,
'perl.string.deref': hi_yellow,
# `` strings # `` strings
'evalstring.start': lo_cyan, 'evalstring.start': lo_cyan,
'evalstring.end': lo_cyan, 'evalstring.end': lo_cyan,
'evalstring.data': hi_cyan, 'evalstring.data': hi_cyan,
'evalstring.null': hi_cyan, 'evalstring.null': hi_cyan,
'evalstring.escaped': hi_magenta,
'evalstring.deref': hi_yellow,
# quoted region # quoted region
'perl.quoted.start': lo_cyan, 'perl.quoted.start': lo_cyan,
'perl.quoted.end': lo_cyan, 'perl.quoted.end': lo_cyan,
'perl.quoted.data': hi_cyan, 'perl.quoted.data': hi_cyan,
'perl.quoted.null': hi_cyan, 'perl.quoted.null': hi_cyan,
'perl.quoted.escaped': hi_magenta,
'perl.quoted.deref': hi_yellow,
# match regex # match regex
'match.start': lo_cyan, 'match.start': lo_cyan,
@ -852,14 +858,12 @@ class Perl(Fundamental):
'match.null': hi_cyan, 'match.null': hi_cyan,
# replace regex # replace regex
'replace.start': lo_cyan, 'replace.start': lo_cyan,
'replace.middle0': lo_cyan, 'replace.middle0': lo_cyan,
'replace.middle1': lo_cyan, 'replace.middle1': lo_cyan,
'replace.end': lo_cyan, 'replace.end': lo_cyan,
'replace.data': hi_cyan, 'replace.data': hi_cyan,
'replace.null': hi_cyan, 'replace.null': hi_cyan,
'replace.escaped': hi_magenta,
'replace.deref': hi_yellow,
# translate regex # translate regex
'translate.start': lo_magenta, 'translate.start': lo_magenta,
@ -870,11 +874,12 @@ class Perl(Fundamental):
} }
config = {} config = {}
lconfig = {'perl.libs': []} lconfig = {'perl.libs': []}
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup, actions = [
PerldocModule, PerldocWord, Perldoc, PerldocF, PerlSetLib, PerlCheckSyntax, PerlHashCleanup, PerldocModule,
PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction, PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerlInitFunctions,
PerlWhichFunction, PerlListFunctions, PerlOpenModule, PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule,
PerlOpenModuleWord, PerlSemanticComplete] PerlOpenModuleWord, PerlSemanticComplete,
]
completers = { completers = {
'perlfunction': PerlFunctionCompleter(None), 'perlfunction': PerlFunctionCompleter(None),
} }
@ -896,7 +901,6 @@ class Perl(Fundamental):
} }
def __init__(self, w): def __init__(self, w):
Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.context = PerlContext(self) self.context = PerlContext(self)
self.functions = None self.functions = None
self.funclines = None self.funclines = None
@ -930,10 +934,12 @@ class Perl(Fundamental):
self.perlinc = data.split('\n') self.perlinc = data.split('\n')
return self.perlinc return self.perlinc
def get_functions(self): return self.context.get_names() def get_functions(self):
def get_function_names(self): return self.context.get_name_list() return self.context.get_names()
def get_line_function(self, y): return self.context.get_line_name(y) def get_function_names(self):
return self.context.get_name_list()
def get_line_function(self, y):
return self.context.get_line_name(y)
def get_status_names(self): def get_status_names(self):
names = Fundamental.get_status_names(self) names = Fundamental.get_status_names(self)
c = self.window.logical_cursor() c = self.window.logical_cursor()