fixed a bug when creating tokens

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-24 13:05:50 +00:00
parent 4beb9427c0
commit ace04216c2
2 changed files with 9 additions and 6 deletions

12
lex3.py
View File

@ -75,12 +75,15 @@ class Rule:
t = Token(name, self, lexer.y, lexer.x, s, None, parent, matchd, link)
t.color = lexer.get_color(t)
lexer.x += len(s)
if lexer.x >= len(lexer.lines[lexer.y]):
if lexer.x > len(lexer.lines[lexer.y]):
lexer.x = 0
lexer.y += 1
return t
def get_line(self, lexer):
return lexer.lines[lexer.y] + '\n'
def get_line(self, lexer, y=None):
if y is None:
return lexer.lines[lexer.y] + '\n'
else:
return lexer.lines[y] + '\n'
class PatternRule(Rule):
def __init__(self, name, pattern):
@ -150,7 +153,7 @@ class PatternGroupRule(PatternRule):
for (tokname, tokre) in self.pairs:
if y >= len(lexer.lines):
return []
line = lexer.lines[y] + '\n'
line = self.get_line(lexer, y)
m = tokre.match(line, x)
if m:
x += len(m.group(0))
@ -161,7 +164,6 @@ class PatternGroupRule(PatternRule):
else:
return []
assert len(matches) == len(self.pairs)
#(lexer.x, lexer.y) = (x, y)
return matches
def lex(self, lexer, parent, matches):
if matches:

View File

@ -19,7 +19,8 @@ class PathGrammar(Grammar):
PatternGroupRule(r'fields', r'owner', r'[^ ]+ +', r'group', r'[^ ]+ +',
r'size', r'[^ ]+ +',
r'mtime', r'[A-Za-z]{3} [ 0-9]{2} [0-9]{2}:[0-9]{2} +',
r'name', r'[^\n]*'),
r'name', r'[^\n]*',
),
]
class DirGrammar(Grammar):