mirror of
https://github.com/lloeki/wasp.git
synced 2025-12-06 10:44:39 +01:00
pos might be undefined
This commit is contained in:
parent
457e24fb31
commit
ba160588a0
2 changed files with 8 additions and 2 deletions
3
test.py
3
test.py
|
|
@ -36,6 +36,9 @@ class TestParser(TestCase):
|
||||||
self.assertEqual(str(parser.parse("(+ '1 (* 3 2))")),
|
self.assertEqual(str(parser.parse("(+ '1 (* 3 2))")),
|
||||||
"(+ . ('1 . ((* . (3 . (2 . NIL))) . NIL)))")
|
"(+ . ('1 . ((* . (3 . (2 . NIL))) . NIL)))")
|
||||||
|
|
||||||
|
def test_error_unclosed_list(self):
|
||||||
|
self.assertRaises(ValueError, parser.parse("(42"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import unittest
|
import unittest
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,11 @@ pg = ParserGenerator(["QUOTE", "LPAREN", "RPAREN", "ATOM"],
|
||||||
def error_handler(token):
|
def error_handler(token):
|
||||||
type = token.gettokentype()
|
type = token.gettokentype()
|
||||||
pos = token.getsourcepos()
|
pos = token.getsourcepos()
|
||||||
raise ValueError("unexpected %s at (%s, %s)" %
|
if pos is None:
|
||||||
(type, pos.lineno, pos.colno))
|
raise ValueError("unexpected %s" % type)
|
||||||
|
else:
|
||||||
|
raise ValueError("unexpected %s at (%s, %s)" %
|
||||||
|
(type, pos.lineno, pos.colno))
|
||||||
|
|
||||||
|
|
||||||
@pg.production("main : sexpr")
|
@pg.production("main : sexpr")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue