Fix a crash when tokenizing a single quote

This commit is contained in:
Kodi Arfer 2017-04-06 17:28:59 -07:00 committed by Tuukka Turto
parent bb9f543246
commit 286d568959
4 changed files with 15 additions and 3 deletions

1
NEWS
View File

@ -23,6 +23,7 @@ Changes from 0.12.1
* `setv` no longer unnecessarily tries to get attributes
* `loop` no longer replaces string literals equal to "recur"
* The REPL now prints the correct value of `do` and `try` forms
* Fixed a crash when tokenizing a single quote followed by whitespace
[ Misc. Improvements ]
* New contrib module `hy-repr`

View File

@ -34,7 +34,7 @@ def tokenize(buf):
except LexingError as e:
pos = e.getsourcepos()
raise LexException("Could not identify the next token.",
pos.lineno, pos.colno)
pos.lineno, pos.colno, buf)
except LexException as e:
if e.source is None:
e.source = buf

View File

@ -24,12 +24,12 @@ from hy.errors import HyError
class LexException(HyError):
"""Error during the Lexing of a Hython expression."""
def __init__(self, message, lineno, colno):
def __init__(self, message, lineno, colno, source=None):
super(LexException, self).__init__(message)
self.message = message
self.lineno = lineno
self.colno = colno
self.source = None
self.source = source
self.filename = '<stdin>'
def __str__(self):

View File

@ -63,6 +63,17 @@ def test_unbalanced_exception():
pass
def test_lex_single_quote_err():
"Ensure tokenizing \"' \" throws a LexException that can be stringified"
# https://github.com/hylang/hy/issues/1252
try:
tokenize("' ")
except LexException as e:
assert "Could not identify the next token" in str(e)
else:
assert False
def test_lex_expression_symbols():
""" Make sure that expressions produce symbols """
objs = tokenize("(foo bar)")