From 34f81cdb0de21da558b413b55118905cad3ad1ef Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Sun, 26 Jul 2009 22:50:12 -0400 Subject: [PATCH] improved perl grammar and some clean up --HG-- branch : pmacs2 --- application.py | 5 +- mode/perl.py | 400 +++++++++++++++++++++++++------------------------ 2 files changed, 205 insertions(+), 200 deletions(-) diff --git a/application.py b/application.py index 2a62692..779dac7 100755 --- a/application.py +++ b/application.py @@ -213,14 +213,13 @@ class Application(object): curses.def_prog_mode() 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['max_error_len'] = 192 self.config['max_num_kills'] = 64 self.config['word_letters'] = string.ascii_letters + string.digits self.config['default_color'] = ('default', 'default',) - self.config['margin'] = 80 + self.config['margin'] = 79 self.config['margin_color'] = 'blue' self.config['use_last_replace'] = False diff --git a/mode/perl.py b/mode/perl.py index bd2e935..266af45 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -16,6 +16,8 @@ from tab import StackTabber, StackTabber2 from parse import Any, And, Or, Optional, Name, Match, Matchs import term +class PerlGrammar(Grammar): pass + class WhitespaceGrammar(Grammar): rules = [ PatternRule('spaces', ' +'), @@ -49,16 +51,21 @@ def _make_string_rules(forbidden): rules = [ PatternRule('octal', r'\\[0-7]{3}'), PatternRule('escaped', r'\\.'), - PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + - hword + "|" + strg1 + "|" + strg2 + ")}|" + - "(?:->)?\[\$?"+hword+"\]"+ ")+"), + #PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" + + # hword + "|" + strg1 + "|" + strg2 + ")}|" + + # "(?:->)?\[\$?"+hword+"\]"+ ")+"), 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), + + 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 == ')': rules.append(PatternRule('data', r"\([^$%@\(\)]*\)")) @@ -87,7 +94,7 @@ class StrictStringGrammar(Grammar): rules = [ PatternRule('data', r"[^\\']+"), ] class StringGrammar(Grammar): - rules = _make_string_rules('"') + [PatternRule('data', r'[^$%@\\"]+')] + rules = _make_string_rules('"') #+ [PatternRule('data', r'[^$%@\\"]+')] class EvalGrammar(Grammar): 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 QuotedGrammar4(Grammar): rules = _make_string_rules(']') -class PerlGrammar(Grammar): - rules = [ - 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$'), +PerlGrammar.rules = [ + 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('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''), - RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'), + RegionRule('perl.endblock', "^__END__|__DATA__ *$", DataGrammar, ''), + RegionRule('perl.pod', '^=' + word1, PodGrammar, '^=cut'), - OverridePatternRule('perl.comment', '#@@:(?P' + pname + - '):(?P' + pname + ') *$'), + OverridePatternRule('perl.comment', '#@@:(?P' + pname + + '):(?P' + pname + ') *$'), - PatternMatchRule('x', '(sub)( +)(' + word2 + - r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', - 'perl.keyword', 'spaces', 'perl.sub', 'spaces', - 'delimiter', 'spaces', 'perl.prototype', - 'spaces', 'delimiter'), + PatternMatchRule('x', '(sub)( +)(' + word2 + + r')( *)(\()( *)([\[\]\\@$%&*;]+)( *)(\))', + 'perl.keyword', 'spaces', 'perl.sub', 'spaces', + 'delimiter', 'spaces', 'perl.prototype', + 'spaces', 'delimiter'), - PatternRule('perl.comment', '#.*$'), - RegionRule('perl.string', '"', StringGrammar, '"'), - RegionRule('perl.string', "'", StrictStringGrammar, "'"), - 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.reserved', "(?)(?:STDIN|STDERR|STDOUT|__PACKAGE__)(?![a-zA-Z0-9_])"), - PatternRule('perl.hashkey', '(?<={)' + wchr2 + '+(?=})'), - PatternRule('perl.method', '(?<=->)' + word1), - PatternRule('perl.hashkey', wchr2 + '+(?= *=>)'), - PatternRule('perl.length', r"\$#" + word2), - #PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), + PatternRule('perl.comment', '#.*$'), + RegionRule('perl.string', '"', StringGrammar, '"'), + RegionRule('perl.string', "'", StrictStringGrammar, "'"), + 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.reserved', "(?)(?:STDIN|STDERR|STDOUT|__PACKAGE__)(?![a-zA-Z0-9_])"), + PatternRule('perl.hashkey', '(?<={)' + wchr2 + '+(?=})'), + PatternRule('perl.method', '(?<=->)' + word1), + PatternRule('perl.hashkey', wchr2 + '+(?= *=>)'), + PatternRule('perl.length', r"\$#" + word2), + #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]+)?'), + 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 + '(?= *\{)'), + # 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 + ')'), - PatternRule('perl.scalar', r'\$\^O'), - PatternRule('perl.scalar', r'\${\^' + word1 + '}'), + PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'), + PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'), + PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'), + PatternRule('perl.scalar', r'\$\^O'), + PatternRule('perl.scalar', r'\${\^' + word1 + '}'), - PatternRule('perl.array', r'\@[\+\-]'), - PatternRule('perl.hash', r'\%(?:[!]|^H)'), + PatternRule('perl.array', r'\@[\+\-]'), + PatternRule('perl.hash', r'\%(?:[!]|^H)'), - PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + - wchr2 + ")"), - PatternRule('perl.array', r"\@_"), - PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), - PatternRule('perl.scalar', r"\$[0-9]+"), - PatternRule('perl.scalar', r"\$\$*" + word2), - PatternRule('perl.array', r"\@(?= *{)"), - PatternRule('perl.array', r"\@\$*" + word2), - PatternRule('perl.hash', r"\%(?= *{)"), - PatternRule('perl.hash', r"\%\$*" + word2), + PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + + wchr2 + ")"), + PatternRule('perl.array', r"\@_"), + PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), + PatternRule('perl.scalar', r"\$[0-9]+"), + PatternRule('perl.scalar', 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\()', - 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; paired delimiters + 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; standard delimiters - 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_])', - MatchGrammar0, '%(delim)s[a-z]*'), - RegionRule('perl.match', 'm(?P#)', MatchGrammar2, '#[a-z]*'), + # match regexes; standard delimiters + 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_])', + MatchGrammar0, '%(delim)s[a-z]*'), + RegionRule('perl.match', 'm(?P#)', MatchGrammar2, '#[a-z]*'), - # replace regexes; paired delimiters - RegionRule('perl.replace', r's *(?P\()', MatchGrammar3, - r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'), - RegionRule('perl.replace', r's *(?P\[)', MatchGrammar4, - r'\]', WhitespaceGrammar, '\[', MatchGrammar4, r'\][a-z]*'), - RegionRule('perl.replace', r's *(?P\{)', MatchGrammar5, - r'\}', WhitespaceGrammar, '\{', MatchGrammar5, r'\}[a-z]*'), - RegionRule('perl.replace', r's *(?P\<)', MatchGrammar6, - r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'), + # replace regexes; paired delimiters + RegionRule('perl.replace', r's *(?P\()', MatchGrammar3, + r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'), + RegionRule('perl.replace', r's *(?P\[)', MatchGrammar4, + r'\]', WhitespaceGrammar, '\[', MatchGrammar4, r'\][a-z]*'), + RegionRule('perl.replace', r's *(?P\{)', MatchGrammar5, + r'\}', WhitespaceGrammar, '\{', MatchGrammar5, r'\}[a-z]*'), + RegionRule('perl.replace', r's *(?P\<)', MatchGrammar6, + r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'), - # replace regexes; standard delimiters - RegionRule('perl.replace', 's *(?P/)', MatchGrammar1, - '/', MatchGrammar1, '/[a-z]*'), - RegionRule('perl.replace', 's *(?P[^ a-zA-Z0-9_])', - MatchGrammar0, '%(delim)s', - MatchGrammar0, '%(delim)s[a-z]*'), - RegionRule('perl.replace', 's(?P#)', - MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'), + # replace regexes; standard delimiters + RegionRule('perl.replace', 's(?P#)', + MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'), + RegionRule('perl.replace', 's *(?P/)', + MatchGrammar1, '/', MatchGrammar1, '/[a-z]*'), + RegionRule('perl.replace', 's *(?P[^ a-zA-Z0-9_])', + MatchGrammar0, '%(delim)s', + MatchGrammar0, '%(delim)s[a-z]*'), - # translate operator - 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]*'), + # translate operator + 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('perl.package', "(?<=package )" + word2), - PatternRule('perl.sub', "(?<=sub )" + word2), - PatternRule('perl.use', "(?<=use )" + word2), - 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_])"), + # some more basic stuff + PatternRule('perl.package', "(?<=package )" + word2), + PatternRule('perl.sub', "(?<=sub )" + word2), + PatternRule('perl.use', "(?<=use )" + word2), + 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_])"), - # quote operator: qq(), qx() and qr() usually interpolate - 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#)', MatchGrammar0, '#'), - RegionRule('perl.quoted', 'q[rqx] *(?P[^ a-zA-Z0-9#])', MatchGrammar0, '%(delim)s'), + # quote operator: qq(), qx() and qr() usually interpolate + 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#)', MatchGrammar0, '#'), + RegionRule('perl.quoted', 'q[rqx] *(?P[^ a-zA-Z0-9#])', MatchGrammar0, '%(delim)s'), - # quote operator: q() and qw() do not interpolate - 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'), + # quote operator: q() and qw() do not interpolate + 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('perl.function', word2 + r"(?= *\()"), - PatternRule('perl.class', word2 + "(?=->)"), + PatternRule('perl.function', word2 + r"(?= *\()"), + PatternRule('perl.class', word2 + "(?=->)"), - PatternRule('perl.glob', r'\*(?= *{)'), - PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2), + PatternRule('perl.glob', r'\*(?= *{)'), + PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2), - # some basic stuff - PatternRule('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), + # some basic stuff + PatternRule('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('spaces', ' +'), - PatternRule('eol', r"\n$"), - ] + PatternRule('spaces', ' +'), + PatternRule('eol', r"\n$"), +] class PerlTabber(StackTabber2): is_ignored_tokens = ('spaces', 'eol', 'perl.comment') @@ -731,6 +737,22 @@ class PerlContext(context.Context): # white is for delimiters, operators, numbers 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 lo_green = ('green020', 'default', 'bold') hi_green = ('green050', 'default', 'bold') @@ -739,19 +761,6 @@ hi_green = ('green050', 'default', 'bold') lo_cyan = ('cyan022', '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 lo_blue = ('blue113', 'default', 'bold') hi_blue = ('blue225', 'default', 'bold') @@ -769,11 +778,7 @@ class Perl(Fundamental): closetags = {')': '(', ']': '[', '}': '{'} colors = { # comments - 'perl.comment': hi_red, - 'endblock.start': lo_red, - 'endblock.end': hi_red, - 'endblock.data': hi_red, - 'endblock.null': hi_red, + 'perl.comment': hi_red, # pod 'pod.start': hi_red, @@ -786,18 +791,19 @@ class Perl(Fundamental): 'pod.entry.null': hi_magenta, # basic stuff - 'perl.sub': hi_cyan, - 'perl.prototype': hi_yellow, + 'perl.glob': hi_magenta, 'perl.noperator': hi_magenta, 'perl.keyword': hi_magenta, 'perl.builtin': hi_magenta, 'perl.reserved': hi_magenta, + 'perl.prototype': hi_yellow, 'perl.scalar': hi_yellow, 'perl.length': hi_yellow, - 'perl.deref': hi_yellow, - 'perl.array': lo_yellow, + #'perl.deref': hi_yellow, + 'perl.array': hi_orange, 'perl.hash': lo_orange, 'perl.hashkey': hi_green, + 'perl.sub': hi_cyan, 'perl.method': hi_cyan, 'perl.function': hi_cyan, 'perl.label': hi_cyan, @@ -805,14 +811,20 @@ class Perl(Fundamental): 'perl.class': hi_cyan, 'perl.use': 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.end': lo_green, 'heredoc.data': hi_green, 'heredoc.null': hi_green, + # evaldoc 'evaldoc.start': lo_cyan, 'evaldoc.end': lo_cyan, 'evaldoc.data': hi_cyan, @@ -822,28 +834,22 @@ class Perl(Fundamental): 'perl.number': default, # strings - 'perl.string.start': lo_green, - 'perl.string.end': lo_green, - 'perl.string.data': hi_green, - 'perl.string.null': hi_green, - 'perl.string.escaped': hi_magenta, - 'perl.string.deref': hi_yellow, + 'perl.string.start': lo_green, + 'perl.string.end': lo_green, + 'perl.string.data': hi_green, + 'perl.string.null': hi_green, # `` strings - 'evalstring.start': lo_cyan, - 'evalstring.end': lo_cyan, - 'evalstring.data': hi_cyan, - 'evalstring.null': hi_cyan, - 'evalstring.escaped': hi_magenta, - 'evalstring.deref': hi_yellow, + 'evalstring.start': lo_cyan, + 'evalstring.end': lo_cyan, + 'evalstring.data': hi_cyan, + 'evalstring.null': hi_cyan, # quoted region - 'perl.quoted.start': lo_cyan, - 'perl.quoted.end': lo_cyan, - 'perl.quoted.data': hi_cyan, - 'perl.quoted.null': hi_cyan, - 'perl.quoted.escaped': hi_magenta, - 'perl.quoted.deref': hi_yellow, + 'perl.quoted.start': lo_cyan, + 'perl.quoted.end': lo_cyan, + 'perl.quoted.data': hi_cyan, + 'perl.quoted.null': hi_cyan, # match regex 'match.start': lo_cyan, @@ -852,14 +858,12 @@ class Perl(Fundamental): 'match.null': hi_cyan, # replace regex - 'replace.start': lo_cyan, - 'replace.middle0': lo_cyan, - 'replace.middle1': lo_cyan, - 'replace.end': lo_cyan, - 'replace.data': hi_cyan, - 'replace.null': hi_cyan, - 'replace.escaped': hi_magenta, - 'replace.deref': hi_yellow, + 'replace.start': lo_cyan, + 'replace.middle0': lo_cyan, + 'replace.middle1': lo_cyan, + 'replace.end': lo_cyan, + 'replace.data': hi_cyan, + 'replace.null': hi_cyan, # translate regex 'translate.start': lo_magenta, @@ -870,11 +874,12 @@ class Perl(Fundamental): } config = {} lconfig = {'perl.libs': []} - actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup, - PerldocModule, PerldocWord, Perldoc, PerldocF, - PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction, - PerlWhichFunction, PerlListFunctions, PerlOpenModule, - PerlOpenModuleWord, PerlSemanticComplete] + actions = [ + PerlSetLib, PerlCheckSyntax, PerlHashCleanup, PerldocModule, + PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerlInitFunctions, + PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule, + PerlOpenModuleWord, PerlSemanticComplete, + ] completers = { 'perlfunction': PerlFunctionCompleter(None), } @@ -896,7 +901,6 @@ class Perl(Fundamental): } def __init__(self, w): Fundamental.__init__(self, w) - self.context = PerlContext(self) self.functions = None self.funclines = None @@ -930,10 +934,12 @@ class Perl(Fundamental): self.perlinc = data.split('\n') return self.perlinc - def get_functions(self): return self.context.get_names() - 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_functions(self): + return self.context.get_names() + 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): names = Fundamental.get_status_names(self) c = self.window.logical_cursor()