From ace04216c26c58eca7fca193b24f07a6b4617835 Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 24 Jul 2007 13:05:50 +0000 Subject: [PATCH] fixed a bug when creating tokens --HG-- branch : pmacs2 --- lex3.py | 12 +++++++----- mode/dir.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) 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):