From 691f454dbef25b53da9fd036e5a2986d51b18e83 Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 10 Jul 2007 23:01:44 +0000 Subject: [PATCH] some mode changes --HG-- branch : pmacs2 --- mode_bds.py | 23 +++++++++-------------- mode_perl.py | 49 +++++++++++++++++++++++-------------------------- mode_python.py | 12 +++++------- mode_replace.py | 10 ++++++++-- mode_xml.py | 13 +++++-------- 5 files changed, 50 insertions(+), 57 deletions(-) diff --git a/mode_bds.py b/mode_bds.py index c77d437..88cf2f2 100644 --- a/mode_bds.py +++ b/mode_bds.py @@ -1,17 +1,13 @@ import color, lex2, mode2 -from lex2 import Grammar, PatternRule, RegionRule - -class StringGrammar(Grammar): - rules = [ - PatternRule(r'octal', r'\\[0-7]{3}'), - PatternRule(r'escaped', r'\\.'), - ] -lex2.add('xml-string', StringGrammar) +from lex2 import Grammar, PatternRule, RegionRule, Grammar +from mode_perl import PerlGrammar +from mode_xml import OpenTagGrammar +from mode_perl import StringGrammar class BDSGrammar(Grammar): rules = [ - RegionRule(r'comment', r''), - RegionRule(r'opentag', r'<', lex2.get('xml-opentag'), r'/?>'), + RegionRule(r'comment', r''), + RegionRule(r'opentag', r'<', OpenTagGrammar, r'/?>'), PatternRule(r'closetag', r'< */ *[ =>\n]+ *>'), PatternRule(r'delimiter', r'[\[\]\{\}\(\),\?:]'), PatternRule(r'derived', r'(?:FM|CD|FS|FM|TA)[0-9]{3}-[0-9]{3}-[0-9]{3}'), @@ -20,14 +16,13 @@ class BDSGrammar(Grammar): PatternRule(r'perlfunc', r'[a-zA-Z_][a-zA-Z0-9_]+(?= *\()'), PatternRule(r'misquoted', r"'[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3}(?::[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3})?'"), PatternRule(r'misquoted', r'"[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3}(?::[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3})?"'), - RegionRule(r'string', '"', lex2.get('perl-string'), '"'), - RegionRule(r'string', "'", lex2.get('null'), "'"), + RegionRule(r'string', '"', StringGrammar, '"'), + RegionRule(r'string', "'", Grammar, "'"), PatternRule(r'operator', r'(?:>=|<=|>|<|==|&&|\|\||eq|ne)'), ] -lex2.add('bds', BDSGrammar) class BDS(mode2.Fundamental): - grammar = lex2.get('bds') + grammar = BDSGrammar opentoken = 'delimiter' opentags = {'(': ')', '[': ']', '{': '}'} closetoken = 'delimiter' diff --git a/mode_perl.py b/mode_perl.py index f7bead5..e415168 100644 --- a/mode_perl.py +++ b/mode_perl.py @@ -12,7 +12,6 @@ class PodGrammar(Grammar): PatternRule(r'entry', r'(?:(?<=^=begin)|(?<=^=end)) +.*$'), PatternRule(r'entry', r'(?<=^=encoding) +.*$'), ] -lex2.add('perl-pod', PodGrammar) class StringGrammar(Grammar): rules = [ @@ -25,22 +24,21 @@ class StringGrammar(Grammar): PatternRule(r'cast', r"[\$\@\%\&]{.*?}"), PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), ] -lex2.add('perl-string', StringGrammar) class PerlGrammar(Grammar): rules = [ - RegionRule(r'heredoc1', r"<<(?P[a-zA-Z0-9_]+) *;", lex2.get('perl-string'), r'^%(heredoc)s$'), - RegionRule(r'heredoc1', r'<< *"(?P[a-zA-Z0-9_]+)" *;', lex2.get('perl-string'), r'^%(heredoc)s$'), - RegionRule(r'heredoc2', r"<< *'(?P[a-zA-Z0-9_]+)' *;", lex2.get('null'), r'^%(heredoc)s$'), - RegionRule(r'eval_heredoc', r"<< *`(?P[a-zA-Z0-9_]+)` *;", lex2.get('perl-string'), r'^%(heredoc)s$'), + RegionRule(r'heredoc1', r"<<(?P[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc1', r'<< *"(?P[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc2', r"<< *'(?P[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'), + RegionRule(r'eval_heredoc', r"<< *`(?P[a-zA-Z0-9_]+)` *;", StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'endblock', r"^__END__|__DATA__ *$", lex2.get('null'), r''), - RegionRule(r'pod', r'^=[a-zA-Z0-9_]+', lex2.get('perl-pod'), r'^=cut'), + RegionRule(r'endblock', r"^__END__|__DATA__ *$", Grammar, r''), + RegionRule(r'pod', r'^=[a-zA-Z0-9_]+', PodGrammar, r'^=cut'), PatternRule(r'comment', r'#.*$'), - RegionRule(r'string1', r'"', lex2.get('perl-string'), r'"'), - RegionRule(r'string2', r"'", lex2.get('null'), r"'"), - RegionRule(r'evalstring', r"`", lex2.get('perl-string'), r"`"), + RegionRule(r'string1', r'"', StringGrammar, r'"'), + RegionRule(r'string2', r"'", Grammar, r"'"), + RegionRule(r'evalstring', r"`", StringGrammar, r"`"), PatternRule(r'number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), PatternRule(r'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'(?<={)[A-Za-z0-9_]+(?=})'), @@ -56,17 +54,17 @@ class PerlGrammar(Grammar): PatternRule(r'deref', r"[@%\$&\*](?={)"), # match regexes - RegionRule(r'match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)) *(?P/)', lex2.get('perl-string'), r'/[a-z]*'), - RegionRule(r'match', r'm *(?P[^ #a-zA-Z0-9_])', lex2.get('perl-string'), r'%(delim)s[a-z]*'), - RegionRule(r'match', r'm(?P#)', lex2.get('perl-string'), r'#[a-z]*'), + RegionRule(r'match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)) *(?P/)', StringGrammar, 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#)', StringGrammar, r'#[a-z]*'), # replace regexes - DualRegionRule(r'replace', r's *(?P[^ a-zA-Z0-9_])', lex2.get('perl-string'), r'%(delim)s', lex2.get('perl-string'), r'%(delim)s[a-z]*'), - DualRegionRule(r'replace', r's(?P#)', lex2.get('perl-string'), r'#', lex2.get('perl-string'), r'#[a-z]*'), + DualRegionRule(r'replace', r's *(?P[^ a-zA-Z0-9_])', StringGrammar, r'%(delim)s', StringGrammar, r'%(delim)s[a-z]*'), + DualRegionRule(r'replace', r's(?P#)', StringGrammar, r'#', StringGrammar, r'#[a-z]*'), # translate operator - DualRegionRule(r'translate', r'(?:y|tr) *(?P[^ a-zA-Z0-9_])', lex2.get('null'), r'%(delim)s', lex2.get('null'), r'%(delim)s[a-z]*'), - DualRegionRule(r'translate', r'(?:y|tr)#', lex2.get('null'), r'#', lex2.get('null'), r'#[a-z]*'), + DualRegionRule(r'translate', r'(?:y|tr) *(?P[^ a-zA-Z0-9_])', Grammar, r'%(delim)s', Grammar, r'%(delim)s[a-z]*'), + DualRegionRule(r'translate', r'(?:y|tr)#', Grammar, r'#', Grammar, r'#[a-z]*'), # some more basic stuff PatternRule(r'package', r"(?<=package )(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"), @@ -79,12 +77,12 @@ class PerlGrammar(Grammar): PatternRule(r'builtin', r"(?)&?(?:write|warn|wantarray|waitpid|wait|vec|values|utime|use|untie|unshift|unpack|unlink|undef|umask|ucfirst|uc|truncate|times|time|tied|tie|telldir|tell|syswrite|system|sysseek|sysread|sysopen|syscall|symlink|substr|sub|study|stat|srand|sqrt|sprintf|split|splice|sort|socketpair|socket|sleep|sin|shutdown|shmwrite|shmread|shmget|shmctl|shift|setsockopt|setservent|setpwent|setprotoent|setpriority|setpgrp|setnetent|sethostent|setgrent|send|semop|semget|semctl|select|seekdir|seek|scalar|rmdir|rindex|rewinddir|reverse|return|reset|require|rename|ref|redo|recv|readpipe|readlink|readline|readdir|read|rand|quotemeta|push|prototype|printf|print|pos|pop|pipe|package|pack|our|ord|opendir|open|oct|no|next|my|msgsnd|msgrcv|msgget|msgctl|mkdir|map|lstat|log|lock|localtime|local|listen|link|length|lcfirst|lc|last|kill|keys|join|ioctl|int|index|import|hex|grep|goto|gmtime|glob|getsockopt|getsockname|getservent|getservbyport|getservbyname|getpwuid|getpwnam|getpwent|getprotoent|getprotobynumber|getprotobyname|getpriority|getppid|getpgrp|getpeername|getnetent|getnetbyname|getnetbyaddr|getlogin|gethostent|gethostbyname|gethostbyaddr|getgrnam|getgrgid|getgrent|getc|formline|format|fork|flock|fileno|fcntl|exp|exit|exists|exec|eval|eof|endservent|endpwent|endprotoent|endnetent|endhostent|endgrent|each|dump|do|die|delete|defined|dbmopen|dbmclose|crypt|cos|continue|connect|closedir|close|chroot|chr|chown|chop|chomp|chmod|chdir|caller|bless|binmode|bind|atan2|alarm|accept|abs)(?![a-zA-Z0-9_])"), # quote operator - RegionRule(r'quoted', r'q[rqwx]? *\(', lex2.get('null'), r'\)'), - RegionRule(r'quoted', r'q[rqwx]? *{', lex2.get('null'), r'}'), - RegionRule(r'quoted', r'q[rqwx]? *<', lex2.get('null'), r'>'), - RegionRule(r'quoted', r'q[rqwx]? *\[', lex2.get('null'), r'\]'), - RegionRule(r'quoted', r'q[rqwx]? *(?P[^ #])', lex2.get('null'), r'%(delim)s'), - RegionRule(r'quoted', r'q[rqwx]?#', lex2.get('null'), r'#'), + RegionRule(r'quoted', r'q[rqwx]? *\(', Grammar, r'\)'), + RegionRule(r'quoted', r'q[rqwx]? *{', Grammar, r'}'), + RegionRule(r'quoted', r'q[rqwx]? *<', Grammar, r'>'), + RegionRule(r'quoted', r'q[rqwx]? *\[', Grammar, r'\]'), + RegionRule(r'quoted', r'q[rqwx]? *(?P[^ #])', Grammar, r'%(delim)s'), + RegionRule(r'quoted', r'q[rqwx]?#', Grammar, r'#'), PatternRule(r'function', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()"), PatternRule(r'class', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"), @@ -96,7 +94,6 @@ class PerlGrammar(Grammar): PatternRule(r'operator2', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), PatternRule(r'bareword', r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*') ] -lex2.add('perl', PerlGrammar) class PerlTabber(tab2.StackTabber): def is_base(self, y): @@ -165,7 +162,7 @@ class PerlTabber(tab2.StackTabber): class Perl(mode2.Fundamental): tabbercls = PerlTabber - grammar = lex2.get('perl') + grammar = PerlGrammar opentoken = 'delimiter' opentags = {'(': ')', '[': ']', '{': '}'} closetoken = 'delimiter' diff --git a/mode_python.py b/mode_python.py index 48ec51c..af79e37 100644 --- a/mode_python.py +++ b/mode_python.py @@ -9,7 +9,6 @@ class StringGrammar(Grammar): PatternRule(r'octal', r'\\[0-7]{3}'), PatternRule(r'escaped', r'\\.'), ] -lex2.grammars['string-py'] = StringGrammar class PythonGrammar(Grammar): rules = [ @@ -29,14 +28,13 @@ class PythonGrammar(Grammar): PatternRule(r"integer", r"(?\n]+(?==)'), PatternRule(r'name', r'[^ =>\n]+'), ] -lex2.grammars['xml-opentag'] = OpenTagGrammar - class XMLGrammar(Grammar): rules = [ - RegionRule(r'comment', r''), - RegionRule(r'opentag', r'<', lex2.grammars['xml-opentag'], r'/?>'), + RegionRule(r'comment', r''), + RegionRule(r'opentag', r'<', OpenTagGrammar, r'/?>'), PatternRule(r'closetag', r'< */ *[ =>\n]+ *>'), ] -lex2.grammars['xml'] = XMLGrammar class XML(mode2.Fundamental): - grammar = lex2.grammars['xml'] + grammar = XMLGrammar def __init__(self, w): mode2.Fundamental.__init__(self, w) self.colors = {