diff --git a/lex3.py b/lex3.py index 43bb12a..6056fac 100755 --- a/lex3.py +++ b/lex3.py @@ -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: diff --git a/mode/dir.py b/mode/dir.py index 4878c6e..c07b6da 100644 --- a/mode/dir.py +++ b/mode/dir.py @@ -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):