Throw an error on unbalanced expressions

This commit is contained in:
Nicolas Dandrimont 2013-04-08 00:17:42 +02:00
parent f5dc569de4
commit 806f0d900c
2 changed files with 18 additions and 0 deletions

View File

@ -161,6 +161,9 @@ class ListeyThing(State):
if char == self.end_char:
return Idle
if char in ")]}":
raise LexException("Unexpected closing character: `%s'" % (char))
if char in WHITESPACE:
self.commit()
return

View File

@ -44,6 +44,21 @@ def test_lex_exception():
pass
def test_unbalanced_exception():
"""Ensure the tokenization fails on unbalanced expressions"""
try:
tokenize("(bar))")
assert True is False
except LexException:
pass
try:
tokenize("(baz [quux]])")
assert True is False
except LexException:
pass
def test_lex_expression_symbols():
""" Make sure that expressions produce symbols """
objs = tokenize("(foo bar)")