improvements to tabbing

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-06 04:21:29 +00:00
parent dfa5ff88f3
commit 533e7b53b7
2 changed files with 179 additions and 146 deletions

View File

@ -14,11 +14,12 @@ class PodDataGrammar(Grammar):
class PodGrammar(Grammar): class PodGrammar(Grammar):
rules = [ rules = [
RegionRule(r'entry', r'(?<=^=head[1-4]) +.*$', PodDataGrammar, '^\n$'), RegionRule('entry', '(?<=^=head[1-4]) +.*$', PodDataGrammar, r'^\n$'),
RegionRule(r'entry', r'(?<=^=over) +.*$', PodDataGrammar, '^\n$'), RegionRule('entry', '(?<=^=over) +.*$', PodDataGrammar, r'^\n$'),
RegionRule(r'entry', r'(?<=^=item) +.*$', PodDataGrammar, '^\n$'), RegionRule('entry', '(?<=^=item) +.*$', PodDataGrammar, r'^\n$'),
RegionRule(r'entry', r'(?:(?<=^=begin)|(?<=^=end)) +.*$', PodDataGrammar, '^\n$'), RegionRule('entry', '(?:(?<=^=begin)|(?<=^=end)) +.*$',
RegionRule(r'entry', r'(?<=^=encoding) +.*$', PodDataGrammar, '^\n$'), PodDataGrammar, r'^\n$'),
RegionRule('entry', '(?<=^=encoding) +.*$', PodDataGrammar, r'^\n$'),
] ]
strg1 = r"'(?:\\.|[^'\\])*'" strg1 = r"'(?:\\.|[^'\\])*'"
@ -32,38 +33,40 @@ pname = '[.a-zA-Z0-9_]+'
def _make_string_rules(forbidden): def _make_string_rules(forbidden):
rules = [ rules = [
PatternRule(r'octal', r'\\[0-7]{3}'), PatternRule('octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'), PatternRule('escaped', r'\\.'),
PatternRule(r'deref', r"\$+" + word2 + "(?:"+ PatternRule('deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
"(?:->)?{\$?(?:" + hword + "|" + strg1 + "|" + strg2 + ")}|" + hword + "|" + strg1 + "|" + strg2 + ")}|" +
"(?:->)?\[\$?"+hword+"\]"+ "(?:->)?\[\$?"+hword+"\]"+ ")+"),
")+"), PatternRule('length', r"\$#" + word2),
PatternRule(r'length', r"\$#" + word2), PatternRule('scalar', r"\$\$*" + word2),
PatternRule(r'scalar', r"\$\$*" + word2), PatternRule('cast', r"[\$\@\%\&]{.+?}"),
PatternRule(r'cast', r"[\$\@\%\&]{.+?}"), PatternRule('array', r"@\$*" + word2),
PatternRule(r'array', r"@\$*" + word2),
] ]
return rules return rules
class QuotedWords(Grammar): rules = [ class QuotedWords(Grammar): rules = [
PatternRule(r'data', hword), PatternRule('data', hword),
PatternRule(r'eol', r'\n'), PatternRule('eol', r'\n'),
PatternRule(r'spaces', r' +'), PatternRule('spaces', ' +'),
] ]
class NoParen(Grammar): rules = [PatternRule(r'data', r'[^)]+')] class NoParen(Grammar): rules = [PatternRule('data', '[^)]+')]
class NoBrace(Grammar): rules = [PatternRule(r'data', r'[^\}]+')] class NoBrace(Grammar): rules = [PatternRule('data', r'[^\}]+')]
class NoBracket(Grammar): rules = [PatternRule(r'data', r'[^\]]+')] class NoBracket(Grammar): rules = [PatternRule('data', r'[^\]]+')]
class NoAngle(Grammar): rules = [PatternRule(r'data', r'[^>]+')] class NoAngle(Grammar): rules = [PatternRule('data', '[^>]+')]
class NoHash(Grammar): rules = [PatternRule(r'data', r'[^#]+')] class NoHash(Grammar): rules = [PatternRule('data', '[^#]+')]
class DataGrammar(Grammar): rules = [PatternRule(r'data', r'.+')] class DataGrammar(Grammar): rules = [PatternRule('data', '.+')]
class StrictStringGrammar(Grammar): rules = [PatternRule(r'escaped', r"\\'")] class StrictStringGrammar(Grammar): rules = [PatternRule('escaped', r"\\'")]
class StringGrammar(Grammar): rules = _make_string_rules('"') class StringGrammar(Grammar): rules = _make_string_rules('"')
class EvalGrammar(Grammar): rules = _make_string_rules('`') class EvalGrammar(Grammar): rules = _make_string_rules('`')
class TranslateGrammar1(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\/])")] class TranslateGrammar1(Grammar):
class TranslateGrammar2(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\#])")] rules = [PatternRule('data', r"(?:\\.|[^\\/])")]
class TranslateGrammarX(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\%(delim)s])")] class TranslateGrammar2(Grammar):
rules = [PatternRule('data', r"(?:\\.|[^\\#])")]
class TranslateGrammarX(Grammar):
rules = [PatternRule('data', r"(?:\\.|[^\\%(delim)s])")]
class MatchGrammar1(Grammar): rules = _make_string_rules('/') class MatchGrammar1(Grammar): rules = _make_string_rules('/')
class MatchGrammar2(Grammar): rules = _make_string_rules('#') class MatchGrammar2(Grammar): rules = _make_string_rules('#')
@ -79,122 +82,148 @@ class QuotedGrammar4(Grammar): rules = _make_string_rules(']')
class PerlGrammar(Grammar): class PerlGrammar(Grammar):
rules = [ rules = [
RegionRule(r'heredoc', r"<<(?P<heredoc>" + word1 + ")", None, RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None,
';\n', StringGrammar, r'^%(heredoc)s$'), r';\n', StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'heredoc', r'<< *"(?P<heredoc>[^"]+)"', None, RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None,
';\n', StringGrammar, r'^%(heredoc)s$'), r';\n', StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'heredoc', r"<< *'(?P<heredoc>[^']+)'", None, RegionRule('perl.heredoc', r"<< *'(?P<heredoc>[^']+)'", None,
";\n", DataGrammar, r'^%(heredoc)s$'), r";\n", DataGrammar, r'^%(heredoc)s$'),
RegionRule(r'evaldoc', r"<< *`(?P<heredoc>[^`]+)`", None, RegionRule('perl.evaldoc', r"<< *`(?P<heredoc>[^`]+)`", None,
";\n", StringGrammar, r'^%(heredoc)s$'), r";\n", StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'endblock', r"^__END__|__DATA__ *$", DataGrammar, r''), RegionRule('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''),
RegionRule(r'pod', '^=' + word1, PodGrammar, r'^=cut'), RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'),
OverridePatternRule(r'comment', r'#@@:(?P<token>' + pname + '):(?P<mode>' + pname + ') *$'), OverridePatternRule('perl.comment', '#@@:(?P<token>' + pname +
'):(?P<mode>' + pname + ') *$'),
PatternMatchRule('x', r'(sub)( +)(' + word2 + r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', PatternMatchRule('x', '(sub)( +)(' + word2 +
'perl_keyword', 'spaces', 'sub', 'spaces', 'delimiter', r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))',
'spaces', 'prototype', 'spaces', 'delimiter'), 'perl.keyword', 'spaces', 'perl.sub', 'spaces',
'perl.delimiter', 'spaces', 'perl.prototype',
'spaces', 'perl.delimiter'),
PatternRule(r'comment', r'#.*$'), PatternRule('perl.comment', '#.*$'),
RegionRule(r'perl_string', r'"', StringGrammar, r'"'), RegionRule('perl.string', '"', StringGrammar, '"'),
RegionRule(r'perl_string', r"'", StrictStringGrammar, r"'"), RegionRule('perl.string', "'", StrictStringGrammar, "'"),
RegionRule(r'evalstring', r"`", EvalGrammar, r"`"), RegionRule('perl.evalstring', "`", EvalGrammar, "`"),
PatternRule(r'number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'),
PatternRule(r'perl_keyword', r"(?<!->)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), PatternRule('perl.keyword', "(?<!->)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"),
PatternRule(r'hash_key', r'(?<={)' + wchr2 + '+(?=})'), PatternRule('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'),
PatternRule(r'perl_method', r'(?<=->)' + word1), PatternRule('perl.method', '(?<=->)' + word1),
PatternRule(r'hash_key', wchr2 + r'+(?= *=>)'), PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'),
PatternRule(r'length', r"\$#" + word2), PatternRule('perl.length', r"\$#" + word2),
PatternRule(r'cast', r'[\$\@\%\&\*](?= *{)'), PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'),
PatternRule(r'scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + wchr2 + ")"), PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" +
PatternRule(r'array', r"@_"), wchr2 + ")"),
PatternRule(r'perl_function', r"\$\$*" + word2 + "(?=-> *\()"), PatternRule('perl.array', "@_"),
PatternRule(r'scalar', r"\$\$*" + word2), PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"),
PatternRule(r'array', r"@\$*" + word2), PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule(r'perl_hash', r"%\$*" + word2), PatternRule('perl.array', r"@\$*" + word2),
PatternRule('perl.hash', r"%\$*" + word2),
# match regexes; paired delimiters # match regexes; paired delimiters
RegionRule(r'match', r'm *(?P<delim>\()', MatchGrammar3, r'\)[a-z]*'), RegionRule('perl.match', r'm *(?P<delim>\()',
RegionRule(r'match', r'm *(?P<delim>\[)', MatchGrammar4, r'\][a-z]*'), MatchGrammar3, r'\)[a-z]*'),
RegionRule(r'match', r'm *(?P<delim>\{)', MatchGrammar5, r'\}[a-z]*'), RegionRule('perl.match', r'm *(?P<delim>\[)',
RegionRule(r'match', r'm *(?P<delim>\<)', MatchGrammar6, r'\>[a-z]*'), MatchGrammar4, r'\][a-z]*'),
RegionRule('perl.match', r'm *(?P<delim>\{)',
MatchGrammar5, r'\}[a-z]*'),
RegionRule('perl.match', r'm *(?P<delim>\<)',
MatchGrammar6, r'\>[a-z]*'),
# match regexes # match regexes
RegionRule(r'match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)) *(?P<delim>/)', MatchGrammar1, r'/[a-z]*'), RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)) *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule(r'match', r'm *(?P<delim>/)', MatchGrammar1, r'/[a-z]*'), RegionRule('perl.match', 'm *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule(r'match', r'm *(?P<delim>[^ #a-zA-Z0-9_])', StringGrammar, r'%(delim)s[a-z]*'), RegionRule('perl.match', 'm *(?P<delim>[^ #a-zA-Z0-9_])',
RegionRule(r'match', r'm(?P<delim>#)', MatchGrammar2, r'#[a-z]*'), StringGrammar, '%(delim)s[a-z]*'),
RegionRule('perl.match', 'm(?P<delim>#)', MatchGrammar2, '#[a-z]*'),
# match regexes; paired delimiters # match regexes; paired delimiters
RegionRule(r'replace', r's *(?P<delim>\()', MatchGrammar3, r'\) *\(', MatchGrammar3, r'\)[a-z]*'), RegionRule('perl.replace', r's *(?P<delim>\()', MatchGrammar3,
RegionRule(r'replace', r's *(?P<delim>\[)', MatchGrammar4, r'\] *\[', MatchGrammar4, r'\][a-z]*'), r'\) *\(', MatchGrammar3, r'\)[a-z]*'),
RegionRule(r'replace', r's *(?P<delim>\{)', MatchGrammar5, r'\} *\{', MatchGrammar5, r'\}[a-z]*'), RegionRule('perl.replace', r's *(?P<delim>\[)', MatchGrammar4,
RegionRule(r'replace', r's *(?P<delim>\<)', MatchGrammar6, r'\> *\<', MatchGrammar6, r'\>[a-z]*'), r'\] *\[', MatchGrammar4, r'\][a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\{)', MatchGrammar5,
r'\} *\{', MatchGrammar5, r'\}[a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\<)', MatchGrammar6,
r'\> *\<', MatchGrammar6, r'\>[a-z]*'),
# replace regexes # replace regexes
RegionRule(r'replace', r's *(?P<delim>/)', MatchGrammar1, r'/', MatchGrammar1, r'/[a-z]*'), RegionRule('perl.replace', 's *(?P<delim>/)', MatchGrammar1,
RegionRule(r'replace', r's *(?P<delim>[^ a-zA-Z0-9_])', StringGrammar, r'%(delim)s', StringGrammar, r'%(delim)s[a-z]*'), '/', MatchGrammar1, '/[a-z]*'),
RegionRule(r'replace', r's(?P<delim>#)', MatchGrammar2, r'#', MatchGrammar2, r'#[a-z]*'), RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
StringGrammar, '%(delim)s',
StringGrammar, '%(delim)s[a-z]*'),
RegionRule('perl.replace', 's(?P<delim>#)',
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
# translate operator # translate operator
RegionRule(r'translate', r'(?:y|tr) *(?P<delim>/)', TranslateGrammar1, r'/', TranslateGrammar1, r'/[a-z]*'), RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)',
RegionRule(r'translate', r'(?:y|tr)#', TranslateGrammar2, r'#', TranslateGrammar2, r'#[a-z]*'), TranslateGrammar1, '/', TranslateGrammar1, '/[a-z]*'),
RegionRule(r'translate', r'(?:y|tr) *(?P<delim>[^ a-zA-Z0-9_])', TranslateGrammarX, r'%(delim)s', TranslateGrammarX, r'%(delim)s[a-z]*'), RegionRule('perl.translate', '(?:y|tr)#', TranslateGrammar2,
'#', TranslateGrammar2, '#[a-z]*'),
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>[^ a-zA-Z0-9_])',
TranslateGrammarX, '%(delim)s', TranslateGrammarX,
'%(delim)s[a-z]*'),
# some more basic stuff # some more basic stuff
PatternRule(r'package', r"(?<=package )" + word2), PatternRule('perl.package', "(?<=package )" + word2),
PatternRule(r'sub', r"(?<=sub )" + word2), PatternRule('perl.sub', "(?<=sub )" + word2),
PatternRule(r'use', r"(?<=use )" + word2), PatternRule('perl.use', "(?<=use )" + word2),
PatternRule(r'require', r"(?<=require )" + word2), PatternRule('perl.require', "(?<=require )" + word2),
PatternRule(r'perl_label', word1 + ':(?!:)'), PatternRule('perl.label', word1 + ':(?!:)'),
PatternRule(r'perl_function', r"&\$*" + word2), PatternRule('perl.function', r"&\$*" + word2),
PatternRule(r'perl_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_])"), 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(r'quoted', r'q[rqx] *(?P<delim>\()', QuotedGrammar1, r'\)'), RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\()', QuotedGrammar1, r'\)'),
RegionRule(r'quoted', r'q[rqx] *(?P<delim>{)', QuotedGrammar2, r'}'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim>{)', QuotedGrammar2, '}'),
RegionRule(r'quoted', r'q[rqx] *(?P<delim><)', QuotedGrammar3, r'>'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim><)', QuotedGrammar3, '>'),
RegionRule(r'quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'), RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'),
RegionRule(r'quoted', r"q[rqx] *(?P<delim>')", Grammar, r"'"), RegionRule('perl.quoted', "q[rqx] *(?P<delim>')", Grammar, "'"),
RegionRule(r'quoted', r'q[rqx] *(?P<delim>[^ a-zA-Z0-9#])', StringGrammar, r'%(delim)s'), RegionRule('perl.quoted', 'q[rqx] *(?P<delim>[^ a-zA-Z0-9#])',
RegionRule(r'quoted', r'q[rqx](?P<delim>#)', StringGrammar, r'#'), StringGrammar, '%(delim)s'),
RegionRule('perl.quoted', 'q[rqx](?P<delim>#)', StringGrammar, '#'),
# quote operator: q() and qw() do not interpolate # quote operator: q() and qw() do not interpolate
RegionRule(r'quoted', r'qw? *\(', QuotedWords, r'\)'), RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'),
RegionRule(r'quoted', r'qw? *{', NoBrace, r'}'), RegionRule('perl.quoted', 'qw? *{', NoBrace, '}'),
RegionRule(r'quoted', r'qw? *<', NoAngle, r'>'), RegionRule('perl.quoted', 'qw? *<', NoAngle, '>'),
RegionRule(r'quoted', r'qw? *\[', NoBracket, r'\]'), RegionRule('perl.quoted', r'qw? *\[', NoBracket, r'\]'),
RegionRule(r'quoted', r'qw?#', NoHash, r'#'), RegionRule('perl.quoted', 'qw?#', NoHash, '#'),
RegionRule(r'quoted', r'qw? *(?P<delim>[^ a-zA-Z0-9#])', Grammar, r'%(delim)s'), RegionRule('perl.quoted', 'qw? *(?P<delim>[^ a-zA-Z0-9#])',
Grammar, '%(delim)s'),
PatternRule(r'perl_function', word2 + "(?= *\()"), PatternRule('perl.function', word2 + r"(?= *\()"),
PatternRule(r'perl_class', word2 + "(?=->)"), PatternRule('perl.class', word2 + "(?=->)"),
# some basic stuff # some basic stuff
PatternRule(r'delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"), PatternRule('perl.delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
PatternRule(r'noperator', r"-[rwxoRWXOezsfdlpSbctugkTBMAC](?!" + wchr2 + ")"), PatternRule('perl.noperator', "-[rwxoRWXOezsfdlpSbctugkTBMAC](?!" +
PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"), wchr2 + ")"),
PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"), PatternRule('perl.operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*=|\\"),
PatternRule(r'noperator', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), PatternRule('perl.operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"),
PatternRule(r'bareword', word2), PatternRule('perl.noperator', "(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"),
PatternRule('perl.bareword', word2),
PatternRule(r'spaces', r' +'), PatternRule('spaces', ' +'),
PatternRule(r"eol", r"\n$"), PatternRule('eol', r"\n$"),
] ]
class PerlTabber2(StackTabber2): class PerlTabber2(StackTabber2):
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} is_ignored_tokens = ('spaces', 'eol', 'perl.comment')
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} open_tokens = {'perl.delimiter': {'{': '}', '(': ')', '[': ']'}}
end_at_eof = False close_tokens = {'perl.delimiter': {'}': '{', ')': '(', ']': '['}}
end_at_tokens = {'delimiter': {';': 1}} end_at_eof = False
nocontinue_tokens = {'delimiter': {';': 1, ',': 1, '}': 1}, end_at_tokens = {'perl.delimiter': {';': 1}}
'heredoc.end': 1, 'evaldoc.end': 1, 'pod.end': 1} nocontinue_tokens = {'perl.delimiter': {';': 1, ',': 1, '}': 1},
start_free_tokens = {'string.start': 1, 'pod.start': 1, 'heredoc.start': 1, 'perl.heredoc.end': 1,
'evaldoc.start': 1} 'perl.evaldoc.end': 1, 'perl.pod.end': 1}
end_free_tokens = {'string.end': 1, 'pod.end': 1, 'heredoc.end': 1, start_free_tokens = {'perl.string.start': 1, 'perl.pod.start': 1,
'evaldoc.start': 1} 'perl.heredoc.start': 1, 'perl.evaldoc.start': 1}
end_free_tokens = {'perl.string.end': 1, 'perl.pod.end': 1,
'perl.heredoc.end': 1, 'perl.evaldoc.start': 1}
class PerlSetLib(Method): class PerlSetLib(Method):
'''Set the path(s) to find perl modules''' '''Set the path(s) to find perl modules'''
@ -608,7 +637,7 @@ class PerlFunctionCompleter(completer.Completer):
class PerlContext(context.Context): class PerlContext(context.Context):
sub_match = And(Optional(Name('spaces')), sub_match = And(Optional(Name('spaces')),
Match('perl_keyword', 'sub'), Match('perl.keyword', 'sub'),
Name('spaces'), Name('spaces'),
Name('sub')) Name('sub'))
def _regen_stack(self, y): def _regen_stack(self, y):
@ -671,20 +700,20 @@ class Perl(mode.Fundamental):
'prototype': ('yellow', 'default', 'bold'), 'prototype': ('yellow', 'default', 'bold'),
'noperator': ('magenta', 'default', 'bold'), 'noperator': ('magenta', 'default', 'bold'),
'endblock': ('red', 'default', 'bold'), 'endblock': ('red', 'default', 'bold'),
'perl_keyword': ('magenta', 'default', 'bold'), 'perl.keyword': ('magenta', 'default', 'bold'),
'cast': ('yellow', 'default', 'bold'), 'cast': ('yellow', 'default', 'bold'),
'scalar': ('yellow', 'default', 'bold'), 'scalar': ('yellow', 'default', 'bold'),
'length': ('yellow', 'default', 'bold'), 'length': ('yellow', 'default', 'bold'),
'array': ('yellow', 'default', 'bold'), 'array': ('yellow', 'default', 'bold'),
'deref': ('yellow', 'default', 'bold'), 'deref': ('yellow', 'default', 'bold'),
'perl_hash': ('yellow', 'default', 'bold'), 'perl.hash': ('yellow', 'default', 'bold'),
'hash_key': ('green', 'default', 'bold'), 'hash_key': ('green', 'default', 'bold'),
'perl_method': ('cyan', 'default', 'bold'), 'perl.method': ('cyan', 'default', 'bold'),
'perl_function': ('cyan', 'default', 'bold'), 'perl.function': ('cyan', 'default', 'bold'),
'perl_builtin': ('magenta', 'default', 'bold'), 'perl.builtin': ('magenta', 'default', 'bold'),
'perl_label': ('cyan', 'default', 'bold'), 'perl.label': ('cyan', 'default', 'bold'),
'package': ('cyan', 'default', 'bold'), 'package': ('cyan', 'default', 'bold'),
'perl_class': ('cyan', 'default', 'bold'), 'perl.class': ('cyan', 'default', 'bold'),
'use': ('cyan', 'default', 'bold'), 'use': ('cyan', 'default', 'bold'),
'require': ('cyan', 'default', 'bold'), 'require': ('cyan', 'default', 'bold'),
@ -697,11 +726,11 @@ class Perl(mode.Fundamental):
'evaldoc.end': ('cyan', 'default', 'bold'), 'evaldoc.end': ('cyan', 'default', 'bold'),
# strings # strings
'perl_string.start': ('green', 'default', 'bold'), 'perl.string.start': ('green', 'default', 'bold'),
'perl_string.null': ('green', 'default', 'bold'), 'perl.string.null': ('green', 'default', 'bold'),
'perl_string.escaped': ('magenta', 'default', 'bold'), 'perl.string.escaped': ('magenta', 'default', 'bold'),
'perl_string.deref': ('yellow', 'default', 'bold'), 'perl.string.deref': ('yellow', 'default', 'bold'),
'perl_string.end': ('green', 'default', 'bold'), 'perl.string.end': ('green', 'default', 'bold'),
# `` strings # `` strings
'evalstring.start': ('cyan', 'default', 'bold'), 'evalstring.start': ('cyan', 'default', 'bold'),
@ -711,13 +740,13 @@ class Perl(mode.Fundamental):
'evalstring.end': ('cyan', 'default', 'bold'), 'evalstring.end': ('cyan', 'default', 'bold'),
# quoted region # quoted region
'quoted': ('cyan', 'default', 'bold'), 'perl.quoted': ('cyan', 'default', 'bold'),
'quoted.start': ('cyan', 'default', 'bold'), 'perl.quoted.start': ('cyan', 'default', 'bold'),
'quoted.null': ('cyan', 'default', 'bold'), 'perl.quoted.null': ('cyan', 'default', 'bold'),
'quoted.data': ('cyan', 'default', 'bold'), 'perl.quoted.data': ('cyan', 'default', 'bold'),
'quoted.escaped': ('magenta', 'default', 'bold'), 'perl.quoted.escaped': ('magenta', 'default', 'bold'),
'quoted.deref': ('yellow', 'default', 'bold'), 'perl.quoted.deref': ('yellow', 'default', 'bold'),
'quoted.end': ('cyan', 'default', 'bold'), 'perl.quoted.end': ('cyan', 'default', 'bold'),
# match regex # match regex
'match.start': ('cyan', 'default', 'bold'), 'match.start': ('cyan', 'default', 'bold'),
@ -733,7 +762,7 @@ class Perl(mode.Fundamental):
'replace.deref': ('yellow', 'default', 'bold'), 'replace.deref': ('yellow', 'default', 'bold'),
'replace.length': ('yellow', 'default', 'bold'), 'replace.length': ('yellow', 'default', 'bold'),
'replace.scalar': ('yellow', 'default', 'bold'), 'replace.scalar': ('yellow', 'default', 'bold'),
'replace.perl_hash': ('yellow', 'default', 'bold'), 'replace.perl.hash': ('yellow', 'default', 'bold'),
'replace.cast': ('yellow', 'default', 'bold'), 'replace.cast': ('yellow', 'default', 'bold'),
# translate regex # translate regex
@ -745,10 +774,10 @@ class Perl(mode.Fundamental):
config = {} config = {}
lconfig = {'perl.libs': []} lconfig = {'perl.libs': []}
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup, actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
PerldocModule, PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerldocModule, PerldocWord, Perldoc, PerldocF,
PerlInitFunctions, PerlGotoFunction, PerlWhichFunction, PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction,
PerlListFunctions, PerlOpenModule, PerlOpenModuleWord, PerlWhichFunction, PerlListFunctions, PerlOpenModule,
PerlSemanticComplete] PerlOpenModuleWord, PerlSemanticComplete]
completers = { completers = {
'perlfunction': PerlFunctionCompleter(None), 'perlfunction': PerlFunctionCompleter(None),
} }

8
tab.py
View File

@ -240,6 +240,8 @@ class Marker2(object):
return '<Marker2(%r, %r, %r, %r)>' % (self.name, self.type_, self.level, self.y) return '<Marker2(%r, %r, %r, %r)>' % (self.name, self.type_, self.level, self.y)
class StackTabber2(Tabber): class StackTabber2(Tabber):
is_ignored_tokens = ('spaces', 'eol', 'comment')
is_indent_tokens = ('spaces',)
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
close_tokens = {'delimiter': set(['}', ')', ']'])} close_tokens = {'delimiter': set(['}', ')', ']'])}
open_scope_tokens = {'delimiter': set(['{'])} open_scope_tokens = {'delimiter': set(['{'])}
@ -352,9 +354,11 @@ class StackTabber2(Tabber):
self.record[y] = tuple(self.stack) self.record[y] = tuple(self.stack)
def _is_indent(self, t): def _is_indent(self, t):
return t.name == 'spaces' #return t.name == 'spaces'
return t.name in self.is_indent_tokens
def _is_ignored(self, t): def _is_ignored(self, t):
return t.name in ('spaces', 'eol', 'comment') #return t.name in ('spaces', 'eol', 'comment')
return t.name in self.is_ignored_tokens
def _is_close_token(self, t): def _is_close_token(self, t):
return t.string in self.close_tokens.get(t.name, set()) return t.string in self.close_tokens.get(t.name, set())