branch : pmacs2
This commit is contained in:
moculus 2007-06-18 22:22:57 +00:00
parent e41e1ae8e0
commit 49dd8bc386
2 changed files with 21 additions and 9 deletions

13
lex2.py
View File

@ -120,6 +120,12 @@ class ContextPatternRule(PatternRule):
else: else:
return False return False
def xyz(x):
if hasattr(x, 'name'):
return x.name
else:
return x
class RegionRule(Rule): class RegionRule(Rule):
def __init__(self, name, start, grammar, end): def __init__(self, name, start, grammar, end):
assert valid_name_re.match(name), 'invalid name %r' % name assert valid_name_re.match(name), 'invalid name %r' % name
@ -130,6 +136,11 @@ class RegionRule(Rule):
self.end = end self.end = end
self.start_re = re.compile(start) self.start_re = re.compile(start)
for rule in self.grammar.rules:
if not hasattr(rule, 'match'):
print 'DAMN %r' % name
raise Exception, repr(rule)
def resume(self, lexer, toresume): def resume(self, lexer, toresume):
#raise Exception, "%r %r" % (lexer, toresume) #XYZ #raise Exception, "%r %r" % (lexer, toresume) #XYZ
assert toresume, "can't resume without tokens to resume!" assert toresume, "can't resume without tokens to resume!"
@ -459,6 +470,8 @@ class Grammar:
rules = [] rules = []
def __init__(self): def __init__(self):
for rule in self.rules: for rule in self.rules:
if type(rule) in (type(tuple()), type(list())):
print self.rules
if hasattr(rule, 'grammar') and rule.grammar is None: if hasattr(rule, 'grammar') and rule.grammar is None:
rule.grammar = self rule.grammar = self

View File

@ -1,5 +1,5 @@
import re, sets, string, sys import re, sets, string, sys
import color, commands, default, lex2, method, mode2, regex, tab_perl import color, commands, default, lex2, method, mode2, regex
from point2 import Point from point2 import Point
from lex2 import Grammar, ConstantRule, PatternRule, ContextPatternRule, \ from lex2 import Grammar, ConstantRule, PatternRule, ContextPatternRule, \
RegionRule, DualRegionRule RegionRule, DualRegionRule
@ -23,7 +23,7 @@ class StringGrammar(Grammar):
PatternRule(name=r'cast', pattern=r"[\$\@\%\&]{.*?}"), PatternRule(name=r'cast', pattern=r"[\$\@\%\&]{.*?}"),
PatternRule(name=r'array', pattern=r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), PatternRule(name=r'array', pattern=r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"),
PatternRule(name=r'hash', pattern=r"%\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), PatternRule(name=r'hash', pattern=r"%\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"),
], ]
g = Grammar() g = Grammar()
pg = PodGrammar() pg = PodGrammar()
@ -88,17 +88,16 @@ class PerlGrammar(Grammar):
PatternRule(name=r'builtin', pattern=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(name=r'builtin', pattern=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(name=r'class', pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"), PatternRule(name=r'class', pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"),
# nested regions # nested regions
RegionRule(name=r'paren', start=r'\(', grammar=None, end=r'\)'), #RegionRule(name=r'paren', start=r'\(', grammar=None, end=r'\)'),
RegionRule(name=r'brace', start=r'{', grammar=None, end=r'}'), #RegionRule(name=r'brace', start=r'{', grammar=None, end=r'}'),
RegionRule(name=r'bracket', start=r'\[', grammar=None, end=r'\]'), #RegionRule(name=r'bracket', start=r'\[', grammar=None, end=r'\]'),
# some basic stuff # some basic stuff
#PatternRule(name=r'delimiter', pattern=r",|;|->|=>|=|\?|(?<!:):(?!=:)"), #PatternRule(name=r'delimiter', pattern=r",|;|->|=>|=|\?|(?<!:):(?!=:)"),
#PatternRule(name=r'delimiter', pattern=r",|;|->|=>|=|\?|\(|\)|{|}|\[|\](?<!:):(?!=:)"),
PatternRule(name=r'delimiter', pattern=r"[=\?(){}\[\]]|->|=>|(?<!:):(?!=:)"), PatternRule(name=r'delimiter', pattern=r"[=\?(){}\[\]]|->|=>|(?<!:):(?!=:)"),
PatternRule(name=r'operator', pattern=r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule(name=r'operator', pattern=r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(name=r'operator', pattern=r"\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|=~|!~|!=|%|!|\."), PatternRule(name=r'operator', pattern=r"\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|=~|!~|!=|%|!|\."),
PatternRule(name=r'bareword', pattern=r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*'), PatternRule(name=r'bareword', pattern=r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*')
] ]
class Perl(mode2.Fundamental): class Perl(mode2.Fundamental):
@ -106,7 +105,7 @@ class Perl(mode2.Fundamental):
mode2.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.tag_matching = True self.tag_matching = True
self.grammar = lex2_perl.PerlGrammar() self.grammar = PerlGrammar()
self.lexer = lex2.Lexer(self.name(), self.grammar) self.lexer = lex2.Lexer(self.name(), self.grammar)
self.add_action_and_bindings(PerlCheckSyntax(), ('C-c s',)) self.add_action_and_bindings(PerlCheckSyntax(), ('C-c s',))
@ -178,7 +177,7 @@ class Perl(mode2.Fundamental):
'string2.end': color.build('green', 'default'), 'string2.end': color.build('green', 'default'),
# `` strings # `` strings
'evalstring.start.': color.build('cyan', 'default'), 'evalstring.start': color.build('cyan', 'default'),
'evalstring.null': color.build('cyan', 'default'), 'evalstring.null': color.build('cyan', 'default'),
'string1.escaped': color.build('magenta', 'default'), 'string1.escaped': color.build('magenta', 'default'),
'string1.deref': color.build('yellow', 'default'), 'string1.deref': color.build('yellow', 'default'),