From 533e7b53b7e5773135474fbae43903d8fc1fb95f Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 6 Apr 2009 04:21:29 +0000 Subject: [PATCH] improvements to tabbing --HG-- branch : pmacs2 --- mode/perl.py | 317 ++++++++++++++++++++++++++++----------------------- tab.py | 8 +- 2 files changed, 179 insertions(+), 146 deletions(-) diff --git a/mode/perl.py b/mode/perl.py index 75f4262..442c575 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -14,11 +14,12 @@ class PodDataGrammar(Grammar): class PodGrammar(Grammar): rules = [ - RegionRule(r'entry', r'(?<=^=head[1-4]) +.*$', PodDataGrammar, '^\n$'), - RegionRule(r'entry', r'(?<=^=over) +.*$', PodDataGrammar, '^\n$'), - RegionRule(r'entry', r'(?<=^=item) +.*$', PodDataGrammar, '^\n$'), - RegionRule(r'entry', r'(?:(?<=^=begin)|(?<=^=end)) +.*$', PodDataGrammar, '^\n$'), - RegionRule(r'entry', r'(?<=^=encoding) +.*$', PodDataGrammar, '^\n$'), + RegionRule('entry', '(?<=^=head[1-4]) +.*$', PodDataGrammar, r'^\n$'), + RegionRule('entry', '(?<=^=over) +.*$', PodDataGrammar, r'^\n$'), + RegionRule('entry', '(?<=^=item) +.*$', PodDataGrammar, r'^\n$'), + RegionRule('entry', '(?:(?<=^=begin)|(?<=^=end)) +.*$', + PodDataGrammar, r'^\n$'), + RegionRule('entry', '(?<=^=encoding) +.*$', PodDataGrammar, r'^\n$'), ] strg1 = r"'(?:\\.|[^'\\])*'" @@ -32,38 +33,40 @@ pname = '[.a-zA-Z0-9_]+' def _make_string_rules(forbidden): rules = [ - PatternRule(r'octal', r'\\[0-7]{3}'), - PatternRule(r'escaped', r'\\.'), - PatternRule(r'deref', r"\$+" + word2 + "(?:"+ - "(?:->)?{\$?(?:" + hword + "|" + strg1 + "|" + strg2 + ")}|" + - "(?:->)?\[\$?"+hword+"\]"+ - ")+"), - PatternRule(r'length', r"\$#" + word2), - PatternRule(r'scalar', r"\$\$*" + word2), - PatternRule(r'cast', r"[\$\@\%\&]{.+?}"), - PatternRule(r'array', r"@\$*" + word2), + PatternRule('octal', r'\\[0-7]{3}'), + PatternRule('escaped', r'\\.'), + PatternRule('deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + + hword + "|" + strg1 + "|" + strg2 + ")}|" + + "(?:->)?\[\$?"+hword+"\]"+ ")+"), + PatternRule('length', r"\$#" + word2), + PatternRule('scalar', r"\$\$*" + word2), + PatternRule('cast', r"[\$\@\%\&]{.+?}"), + PatternRule('array', r"@\$*" + word2), ] return rules class QuotedWords(Grammar): rules = [ - PatternRule(r'data', hword), - PatternRule(r'eol', r'\n'), - PatternRule(r'spaces', r' +'), + PatternRule('data', hword), + PatternRule('eol', r'\n'), + PatternRule('spaces', ' +'), ] -class NoParen(Grammar): rules = [PatternRule(r'data', r'[^)]+')] -class NoBrace(Grammar): rules = [PatternRule(r'data', r'[^\}]+')] -class NoBracket(Grammar): rules = [PatternRule(r'data', r'[^\]]+')] -class NoAngle(Grammar): rules = [PatternRule(r'data', r'[^>]+')] -class NoHash(Grammar): rules = [PatternRule(r'data', r'[^#]+')] -class DataGrammar(Grammar): rules = [PatternRule(r'data', r'.+')] +class NoParen(Grammar): rules = [PatternRule('data', '[^)]+')] +class NoBrace(Grammar): rules = [PatternRule('data', r'[^\}]+')] +class NoBracket(Grammar): rules = [PatternRule('data', r'[^\]]+')] +class NoAngle(Grammar): rules = [PatternRule('data', '[^>]+')] +class NoHash(Grammar): rules = [PatternRule('data', '[^#]+')] +class DataGrammar(Grammar): rules = [PatternRule('data', '.+')] -class StrictStringGrammar(Grammar): rules = [PatternRule(r'escaped', r"\\'")] -class StringGrammar(Grammar): rules = _make_string_rules('"') -class EvalGrammar(Grammar): rules = _make_string_rules('`') +class StrictStringGrammar(Grammar): rules = [PatternRule('escaped', r"\\'")] +class StringGrammar(Grammar): rules = _make_string_rules('"') +class EvalGrammar(Grammar): rules = _make_string_rules('`') -class TranslateGrammar1(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\/])")] -class TranslateGrammar2(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\#])")] -class TranslateGrammarX(Grammar): rules = [PatternRule(r'data', r"(?:\\.|[^\\%(delim)s])")] +class TranslateGrammar1(Grammar): + rules = [PatternRule('data', r"(?:\\.|[^\\/])")] +class TranslateGrammar2(Grammar): + rules = [PatternRule('data', r"(?:\\.|[^\\#])")] +class TranslateGrammarX(Grammar): + rules = [PatternRule('data', r"(?:\\.|[^\\%(delim)s])")] class MatchGrammar1(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): rules = [ - RegionRule(r'heredoc', r"<<(?P" + word1 + ")", None, - ';\n', StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'heredoc', r'<< *"(?P[^"]+)"', None, - ';\n', StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'heredoc', r"<< *'(?P[^']+)'", None, - ";\n", DataGrammar, r'^%(heredoc)s$'), - RegionRule(r'evaldoc', r"<< *`(?P[^`]+)`", None, - ";\n", StringGrammar, r'^%(heredoc)s$'), + RegionRule('perl.heredoc', r"<<(?P" + word1 + ")", None, + r';\n', StringGrammar, r'^%(heredoc)s$'), + RegionRule('perl.heredoc', r'<< *"(?P[^"]+)"', None, + r';\n', StringGrammar, r'^%(heredoc)s$'), + RegionRule('perl.heredoc', r"<< *'(?P[^']+)'", None, + r";\n", DataGrammar, r'^%(heredoc)s$'), + RegionRule('perl.evaldoc', r"<< *`(?P[^`]+)`", None, + r";\n", StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'endblock', r"^__END__|__DATA__ *$", DataGrammar, r''), - RegionRule(r'pod', '^=' + word1, PodGrammar, r'^=cut'), + RegionRule('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''), + RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'), - OverridePatternRule(r'comment', r'#@@:(?P' + pname + '):(?P' + pname + ') *$'), + OverridePatternRule('perl.comment', '#@@:(?P' + pname + + '):(?P' + pname + ') *$'), - PatternMatchRule('x', r'(sub)( +)(' + word2 + r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', - 'perl_keyword', 'spaces', 'sub', 'spaces', 'delimiter', - 'spaces', 'prototype', 'spaces', 'delimiter'), + PatternMatchRule('x', '(sub)( +)(' + word2 + + r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', + 'perl.keyword', 'spaces', 'perl.sub', 'spaces', + 'perl.delimiter', 'spaces', 'perl.prototype', + 'spaces', 'perl.delimiter'), - PatternRule(r'comment', r'#.*$'), - RegionRule(r'perl_string', r'"', StringGrammar, r'"'), - RegionRule(r'perl_string', r"'", StrictStringGrammar, r"'"), - RegionRule(r'evalstring', r"`", EvalGrammar, r"`"), - PatternRule(r'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(r'hash_key', r'(?<={)' + wchr2 + '+(?=})'), - PatternRule(r'perl_method', r'(?<=->)' + word1), - PatternRule(r'hash_key', wchr2 + r'+(?= *=>)'), - PatternRule(r'length', r"\$#" + word2), - PatternRule(r'cast', r'[\$\@\%\&\*](?= *{)'), - PatternRule(r'scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + wchr2 + ")"), - PatternRule(r'array', r"@_"), - PatternRule(r'perl_function', r"\$\$*" + word2 + "(?=-> *\()"), - PatternRule(r'scalar', r"\$\$*" + word2), - PatternRule(r'array', r"@\$*" + word2), - PatternRule(r'perl_hash', r"%\$*" + word2), + PatternRule('perl.comment', '#.*$'), + RegionRule('perl.string', '"', StringGrammar, '"'), + RegionRule('perl.string', "'", StrictStringGrammar, "'"), + RegionRule('perl.evalstring', "`", EvalGrammar, "`"), + PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-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('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'), + PatternRule('perl.method', '(?<=->)' + word1), + PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'), + PatternRule('perl.length', r"\$#" + word2), + PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), + PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + + wchr2 + ")"), + PatternRule('perl.array', "@_"), + PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), + PatternRule('perl.scalar', r"\$\$*" + word2), + PatternRule('perl.array', r"@\$*" + word2), + PatternRule('perl.hash', r"%\$*" + word2), # match regexes; paired delimiters - RegionRule(r'match', r'm *(?P\()', MatchGrammar3, r'\)[a-z]*'), - RegionRule(r'match', r'm *(?P\[)', MatchGrammar4, r'\][a-z]*'), - RegionRule(r'match', r'm *(?P\{)', MatchGrammar5, r'\}[a-z]*'), - RegionRule(r'match', r'm *(?P\<)', MatchGrammar6, r'\>[a-z]*'), + RegionRule('perl.match', r'm *(?P\()', + MatchGrammar3, r'\)[a-z]*'), + RegionRule('perl.match', r'm *(?P\[)', + MatchGrammar4, r'\][a-z]*'), + RegionRule('perl.match', r'm *(?P\{)', + MatchGrammar5, r'\}[a-z]*'), + RegionRule('perl.match', r'm *(?P\<)', + MatchGrammar6, r'\>[a-z]*'), # match regexes - RegionRule(r'match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)) *(?P/)', MatchGrammar1, r'/[a-z]*'), - RegionRule(r'match', r'm *(?P/)', MatchGrammar1, r'/[a-z]*'), - RegionRule(r'match', r'm *(?P[^ #a-zA-Z0-9_])', StringGrammar, r'%(delim)s[a-z]*'), - RegionRule(r'match', r'm(?P#)', MatchGrammar2, r'#[a-z]*'), + RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)) *(?P/)', MatchGrammar1, '/[a-z]*'), + RegionRule('perl.match', 'm *(?P/)', MatchGrammar1, '/[a-z]*'), + RegionRule('perl.match', 'm *(?P[^ #a-zA-Z0-9_])', + StringGrammar, '%(delim)s[a-z]*'), + RegionRule('perl.match', 'm(?P#)', MatchGrammar2, '#[a-z]*'), # match regexes; paired delimiters - RegionRule(r'replace', r's *(?P\()', MatchGrammar3, r'\) *\(', MatchGrammar3, r'\)[a-z]*'), - RegionRule(r'replace', r's *(?P\[)', MatchGrammar4, r'\] *\[', MatchGrammar4, r'\][a-z]*'), - RegionRule(r'replace', r's *(?P\{)', MatchGrammar5, r'\} *\{', MatchGrammar5, r'\}[a-z]*'), - RegionRule(r'replace', r's *(?P\<)', MatchGrammar6, r'\> *\<', MatchGrammar6, r'\>[a-z]*'), + RegionRule('perl.replace', r's *(?P\()', MatchGrammar3, + r'\) *\(', MatchGrammar3, r'\)[a-z]*'), + RegionRule('perl.replace', r's *(?P\[)', MatchGrammar4, + r'\] *\[', MatchGrammar4, r'\][a-z]*'), + RegionRule('perl.replace', r's *(?P\{)', MatchGrammar5, + r'\} *\{', MatchGrammar5, r'\}[a-z]*'), + RegionRule('perl.replace', r's *(?P\<)', MatchGrammar6, + r'\> *\<', MatchGrammar6, r'\>[a-z]*'), # replace regexes - RegionRule(r'replace', r's *(?P/)', MatchGrammar1, r'/', MatchGrammar1, r'/[a-z]*'), - RegionRule(r'replace', r's *(?P[^ a-zA-Z0-9_])', StringGrammar, r'%(delim)s', StringGrammar, r'%(delim)s[a-z]*'), - RegionRule(r'replace', r's(?P#)', MatchGrammar2, r'#', MatchGrammar2, r'#[a-z]*'), + RegionRule('perl.replace', 's *(?P/)', MatchGrammar1, + '/', MatchGrammar1, '/[a-z]*'), + RegionRule('perl.replace', 's *(?P[^ a-zA-Z0-9_])', + StringGrammar, '%(delim)s', + StringGrammar, '%(delim)s[a-z]*'), + RegionRule('perl.replace', 's(?P#)', + MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'), # translate operator - RegionRule(r'translate', r'(?:y|tr) *(?P/)', TranslateGrammar1, r'/', TranslateGrammar1, r'/[a-z]*'), - RegionRule(r'translate', r'(?:y|tr)#', TranslateGrammar2, r'#', TranslateGrammar2, r'#[a-z]*'), - RegionRule(r'translate', r'(?:y|tr) *(?P[^ a-zA-Z0-9_])', TranslateGrammarX, r'%(delim)s', TranslateGrammarX, r'%(delim)s[a-z]*'), + RegionRule('perl.translate', '(?:y|tr) *(?P/)', + TranslateGrammar1, '/', TranslateGrammar1, '/[a-z]*'), + RegionRule('perl.translate', '(?:y|tr)#', TranslateGrammar2, + '#', TranslateGrammar2, '#[a-z]*'), + RegionRule('perl.translate', '(?:y|tr) *(?P[^ a-zA-Z0-9_])', + TranslateGrammarX, '%(delim)s', TranslateGrammarX, + '%(delim)s[a-z]*'), # some more basic stuff - PatternRule(r'package', r"(?<=package )" + word2), - PatternRule(r'sub', r"(?<=sub )" + word2), - PatternRule(r'use', r"(?<=use )" + word2), - PatternRule(r'require', r"(?<=require )" + word2), - PatternRule(r'perl_label', word1 + ':(?!:)'), - PatternRule(r'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.package', "(?<=package )" + word2), + PatternRule('perl.sub', "(?<=sub )" + word2), + PatternRule('perl.use', "(?<=use )" + word2), + PatternRule('perl.require', "(?<=require )" + word2), + PatternRule('perl.label', word1 + ':(?!:)'), + 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_])"), # quote operator: qq(), qx() and qr() usually interpolate - RegionRule(r'quoted', r'q[rqx] *(?P\()', QuotedGrammar1, r'\)'), - RegionRule(r'quoted', r'q[rqx] *(?P{)', QuotedGrammar2, r'}'), - RegionRule(r'quoted', r'q[rqx] *(?P<)', QuotedGrammar3, r'>'), - RegionRule(r'quoted', r'q[rqx] *(?P\[)', QuotedGrammar4, r'\]'), - RegionRule(r'quoted', r"q[rqx] *(?P')", Grammar, r"'"), - RegionRule(r'quoted', r'q[rqx] *(?P[^ a-zA-Z0-9#])', StringGrammar, r'%(delim)s'), - RegionRule(r'quoted', r'q[rqx](?P#)', StringGrammar, r'#'), + RegionRule('perl.quoted', r'q[rqx] *(?P\()', QuotedGrammar1, r'\)'), + RegionRule('perl.quoted', 'q[rqx] *(?P{)', QuotedGrammar2, '}'), + RegionRule('perl.quoted', 'q[rqx] *(?P<)', QuotedGrammar3, '>'), + RegionRule('perl.quoted', r'q[rqx] *(?P\[)', QuotedGrammar4, r'\]'), + RegionRule('perl.quoted', "q[rqx] *(?P')", Grammar, "'"), + RegionRule('perl.quoted', 'q[rqx] *(?P[^ a-zA-Z0-9#])', + StringGrammar, '%(delim)s'), + RegionRule('perl.quoted', 'q[rqx](?P#)', StringGrammar, '#'), # quote operator: q() and qw() do not interpolate - RegionRule(r'quoted', r'qw? *\(', QuotedWords, r'\)'), - RegionRule(r'quoted', r'qw? *{', NoBrace, r'}'), - RegionRule(r'quoted', r'qw? *<', NoAngle, r'>'), - RegionRule(r'quoted', r'qw? *\[', NoBracket, r'\]'), - RegionRule(r'quoted', r'qw?#', NoHash, r'#'), - RegionRule(r'quoted', r'qw? *(?P[^ a-zA-Z0-9#])', Grammar, r'%(delim)s'), + RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'), + RegionRule('perl.quoted', 'qw? *{', NoBrace, '}'), + RegionRule('perl.quoted', 'qw? *<', NoAngle, '>'), + RegionRule('perl.quoted', r'qw? *\[', NoBracket, r'\]'), + RegionRule('perl.quoted', 'qw?#', NoHash, '#'), + RegionRule('perl.quoted', 'qw? *(?P[^ a-zA-Z0-9#])', + Grammar, '%(delim)s'), - PatternRule(r'perl_function', word2 + "(?= *\()"), - PatternRule(r'perl_class', word2 + "(?=->)"), + PatternRule('perl.function', word2 + r"(?= *\()"), + PatternRule('perl.class', word2 + "(?=->)"), # some basic stuff - PatternRule(r'delimiter', r"::|->|=>|(?>=|<<=|\*\*=|\\"), - PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"), - PatternRule(r'noperator', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), - PatternRule(r'bareword', word2), + PatternRule('perl.delimiter', r"::|->|=>|(?>=|<<=|\*\*=|\\"), + 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.bareword', word2), - PatternRule(r'spaces', r' +'), - PatternRule(r"eol", r"\n$"), + PatternRule('spaces', ' +'), + PatternRule('eol', r"\n$"), ] class PerlTabber2(StackTabber2): - open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} - close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} - end_at_eof = False - end_at_tokens = {'delimiter': {';': 1}} - nocontinue_tokens = {'delimiter': {';': 1, ',': 1, '}': 1}, - 'heredoc.end': 1, 'evaldoc.end': 1, 'pod.end': 1} - start_free_tokens = {'string.start': 1, 'pod.start': 1, 'heredoc.start': 1, - 'evaldoc.start': 1} - end_free_tokens = {'string.end': 1, 'pod.end': 1, 'heredoc.end': 1, - 'evaldoc.start': 1} + is_ignored_tokens = ('spaces', 'eol', 'perl.comment') + open_tokens = {'perl.delimiter': {'{': '}', '(': ')', '[': ']'}} + close_tokens = {'perl.delimiter': {'}': '{', ')': '(', ']': '['}} + end_at_eof = False + end_at_tokens = {'perl.delimiter': {';': 1}} + nocontinue_tokens = {'perl.delimiter': {';': 1, ',': 1, '}': 1}, + 'perl.heredoc.end': 1, + 'perl.evaldoc.end': 1, 'perl.pod.end': 1} + start_free_tokens = {'perl.string.start': 1, 'perl.pod.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): '''Set the path(s) to find perl modules''' @@ -608,7 +637,7 @@ class PerlFunctionCompleter(completer.Completer): class PerlContext(context.Context): sub_match = And(Optional(Name('spaces')), - Match('perl_keyword', 'sub'), + Match('perl.keyword', 'sub'), Name('spaces'), Name('sub')) def _regen_stack(self, y): @@ -671,20 +700,20 @@ class Perl(mode.Fundamental): 'prototype': ('yellow', 'default', 'bold'), 'noperator': ('magenta', 'default', 'bold'), 'endblock': ('red', 'default', 'bold'), - 'perl_keyword': ('magenta', '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'), + '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'), + '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'), + 'perl.class': ('cyan', 'default', 'bold'), 'use': ('cyan', 'default', 'bold'), 'require': ('cyan', 'default', 'bold'), @@ -697,11 +726,11 @@ class Perl(mode.Fundamental): 'evaldoc.end': ('cyan', 'default', 'bold'), # 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': ('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'), # `` strings 'evalstring.start': ('cyan', 'default', 'bold'), @@ -711,13 +740,13 @@ class Perl(mode.Fundamental): 'evalstring.end': ('cyan', 'default', 'bold'), # quoted region - 'quoted': ('cyan', 'default', 'bold'), - 'quoted.start': ('cyan', 'default', 'bold'), - 'quoted.null': ('cyan', 'default', 'bold'), - 'quoted.data': ('cyan', 'default', 'bold'), - 'quoted.escaped': ('magenta', 'default', 'bold'), - 'quoted.deref': ('yellow', 'default', 'bold'), - 'quoted.end': ('cyan', 'default', 'bold'), + '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'), # match regex 'match.start': ('cyan', 'default', 'bold'), @@ -733,7 +762,7 @@ class Perl(mode.Fundamental): 'replace.deref': ('yellow', 'default', 'bold'), 'replace.length': ('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'), # translate regex @@ -745,10 +774,10 @@ class Perl(mode.Fundamental): config = {} lconfig = {'perl.libs': []} actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup, - PerldocModule, PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, - PerlInitFunctions, PerlGotoFunction, PerlWhichFunction, - PerlListFunctions, PerlOpenModule, PerlOpenModuleWord, - PerlSemanticComplete] + PerldocModule, PerldocWord, Perldoc, PerldocF, + PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction, + PerlWhichFunction, PerlListFunctions, PerlOpenModule, + PerlOpenModuleWord, PerlSemanticComplete] completers = { 'perlfunction': PerlFunctionCompleter(None), } diff --git a/tab.py b/tab.py index 3d1024f..ac2a970 100644 --- a/tab.py +++ b/tab.py @@ -240,6 +240,8 @@ class Marker2(object): return '' % (self.name, self.type_, self.level, self.y) class StackTabber2(Tabber): + is_ignored_tokens = ('spaces', 'eol', 'comment') + is_indent_tokens = ('spaces',) open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} close_tokens = {'delimiter': set(['}', ')', ']'])} open_scope_tokens = {'delimiter': set(['{'])} @@ -352,9 +354,11 @@ class StackTabber2(Tabber): self.record[y] = tuple(self.stack) 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): - 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): return t.string in self.close_tokens.get(t.name, set())