Count line and column numbers.

pull/15/head
Jussi Pakkanen 11 years ago
parent f64ba79033
commit e8c6c09717
  1. 7
      tools/cmake2meson.py

@ -50,11 +50,9 @@ class Lexer:
col = 0 col = 0
while(loc < len(code)): while(loc < len(code)):
matched = False matched = False
value = None
for (tid, reg) in self.token_specification: for (tid, reg) in self.token_specification:
mo = reg.match(code, loc) mo = reg.match(code, loc)
if mo: if mo:
curline = lineno
col = mo.start()-line_start col = mo.start()-line_start
matched = True matched = True
loc = mo.end() loc = mo.end()
@ -71,6 +69,9 @@ class Lexer:
yield(Token('id', match_text)) yield(Token('id', match_text))
elif tid == 'eol': elif tid == 'eol':
#yield('eol') #yield('eol')
lineno += 1
col = 1
line_start = mo.end()
pass pass
elif tid == 'varexp': elif tid == 'varexp':
yield(Token('varexp', match_text[2:-1])) yield(Token('varexp', match_text[2:-1]))
@ -78,7 +79,7 @@ class Lexer:
raise RuntimeError('Wharrgarbl') raise RuntimeError('Wharrgarbl')
break break
if not matched: if not matched:
raise RuntimeError('Lexer got confused %d %d' % (lineno, col)) raise RuntimeError('Lexer got confused line %d column %d' % (lineno, col))
class Parser(): class Parser():
def __init__(self, code): def __init__(self, code):

Loading…
Cancel
Save