diff --git a/NEWS b/NEWS index 9ae3612..fd3a1e1 100644 --- a/NEWS +++ b/NEWS @@ -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` diff --git a/hy/lex/__init__.py b/hy/lex/__init__.py index f1a74aa..8a73d87 100644 --- a/hy/lex/__init__.py +++ b/hy/lex/__init__.py @@ -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 diff --git a/hy/lex/exceptions.py b/hy/lex/exceptions.py index 4c4b760..2ef5660 100644 --- a/hy/lex/exceptions.py +++ b/hy/lex/exceptions.py @@ -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 = '' def __str__(self): diff --git a/tests/test_lex.py b/tests/test_lex.py index 9691888..514696b 100644 --- a/tests/test_lex.py +++ b/tests/test_lex.py @@ -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)")