parent
4beb9427c0
commit
ace04216c2
10
lex3.py
10
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):
|
||||
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:
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue