Now can parse all files in test set.

pull/15/head
Jussi Pakkanen 11 years ago
parent 68f990c8da
commit 26583435d5
  1. 23
      parsertest.py

@ -58,7 +58,7 @@ class Lexer:
('dot', re.compile(r'\.')), ('dot', re.compile(r'\.')),
('colon', re.compile(r':')), ('colon', re.compile(r':')),
('equal', re.compile(r'==')), ('equal', re.compile(r'==')),
('nequals', re.compile(r'\!=')), ('nequal', re.compile(r'\!=')),
('assign', re.compile(r'=')), ('assign', re.compile(r'=')),
] ]
@ -359,7 +359,7 @@ class Parser:
def e7(self): def e7(self):
if self.accept('lparen'): if self.accept('lparen'):
e = self.expression() e = self.statement()
self.expect('rparen') self.expect('rparen')
return e return e
elif self.accept('lbracket'): elif self.accept('lbracket'):
@ -460,16 +460,11 @@ class Parser:
return block return block
if __name__ == '__main__': if __name__ == '__main__':
code = open(sys.argv[1]).read() for code in sys.argv[1:]:
# lex = Lexer() parser = Parser(open(code).read())
# try: try:
# for i in lex.lex(code): print(code)
# print('Token:', i.tid, 'Line:', i.lineno, 'Column:', i.colno) parser.parse()
# except ParseException as e: except ParseException as e:
# print('Error line', e.lineno, 'column', e.colno) print('Error', e.text, 'line', e.lineno, 'column', e.colno)
parser = Parser(code)
try:
parser.parse()
except ParseException as e:
print('Error', e.text, 'line', e.lineno, 'column', e.colno)

Loading…
Cancel
Save