pos might be undefined

This commit is contained in:
Loic Nageleisen 2014-01-26 13:06:23 +01:00
parent 457e24fb31
commit ba160588a0
2 changed files with 8 additions and 2 deletions

View file

@ -36,6 +36,9 @@ class TestParser(TestCase):
self.assertEqual(str(parser.parse("(+ '1 (* 3 2))")),
"(+ . ('1 . ((* . (3 . (2 . NIL))) . NIL)))")
def test_error_unclosed_list(self):
self.assertRaises(ValueError, parser.parse("(42"))
if __name__ == '__main__':
import unittest

View file

@ -18,6 +18,9 @@ pg = ParserGenerator(["QUOTE", "LPAREN", "RPAREN", "ATOM"],
def error_handler(token):
type = token.gettokentype()
pos = token.getsourcepos()
if pos is None:
raise ValueError("unexpected %s" % type)
else:
raise ValueError("unexpected %s at (%s, %s)" %
(type, pos.lineno, pos.colno))