parent
4beb9427c0
commit
ace04216c2
12
lex3.py
12
lex3.py
|
@ -75,12 +75,15 @@ class Rule:
|
||||||
t = Token(name, self, lexer.y, lexer.x, s, None, parent, matchd, link)
|
t = Token(name, self, lexer.y, lexer.x, s, None, parent, matchd, link)
|
||||||
t.color = lexer.get_color(t)
|
t.color = lexer.get_color(t)
|
||||||
lexer.x += len(s)
|
lexer.x += len(s)
|
||||||
if lexer.x >= len(lexer.lines[lexer.y]):
|
if lexer.x > len(lexer.lines[lexer.y]):
|
||||||
lexer.x = 0
|
lexer.x = 0
|
||||||
lexer.y += 1
|
lexer.y += 1
|
||||||
return t
|
return t
|
||||||
def get_line(self, lexer):
|
def get_line(self, lexer, y=None):
|
||||||
return lexer.lines[lexer.y] + '\n'
|
if y is None:
|
||||||
|
return lexer.lines[lexer.y] + '\n'
|
||||||
|
else:
|
||||||
|
return lexer.lines[y] + '\n'
|
||||||
|
|
||||||
class PatternRule(Rule):
|
class PatternRule(Rule):
|
||||||
def __init__(self, name, pattern):
|
def __init__(self, name, pattern):
|
||||||
|
@ -150,7 +153,7 @@ class PatternGroupRule(PatternRule):
|
||||||
for (tokname, tokre) in self.pairs:
|
for (tokname, tokre) in self.pairs:
|
||||||
if y >= len(lexer.lines):
|
if y >= len(lexer.lines):
|
||||||
return []
|
return []
|
||||||
line = lexer.lines[y] + '\n'
|
line = self.get_line(lexer, y)
|
||||||
m = tokre.match(line, x)
|
m = tokre.match(line, x)
|
||||||
if m:
|
if m:
|
||||||
x += len(m.group(0))
|
x += len(m.group(0))
|
||||||
|
@ -161,7 +164,6 @@ class PatternGroupRule(PatternRule):
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
assert len(matches) == len(self.pairs)
|
assert len(matches) == len(self.pairs)
|
||||||
#(lexer.x, lexer.y) = (x, y)
|
|
||||||
return matches
|
return matches
|
||||||
def lex(self, lexer, parent, matches):
|
def lex(self, lexer, parent, matches):
|
||||||
if matches:
|
if matches:
|
||||||
|
|
|
@ -19,7 +19,8 @@ class PathGrammar(Grammar):
|
||||||
PatternGroupRule(r'fields', r'owner', r'[^ ]+ +', r'group', r'[^ ]+ +',
|
PatternGroupRule(r'fields', r'owner', r'[^ ]+ +', r'group', r'[^ ]+ +',
|
||||||
r'size', r'[^ ]+ +',
|
r'size', r'[^ ]+ +',
|
||||||
r'mtime', r'[A-Za-z]{3} [ 0-9]{2} [0-9]{2}:[0-9]{2} +',
|
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):
|
class DirGrammar(Grammar):
|
||||||
|
|
Loading…
Reference in New Issue