Fix a crash when tokenizing a single quote
This commit is contained in:
parent
bb9f543246
commit
286d568959
1
NEWS
1
NEWS
@ -23,6 +23,7 @@ Changes from 0.12.1
|
|||||||
* `setv` no longer unnecessarily tries to get attributes
|
* `setv` no longer unnecessarily tries to get attributes
|
||||||
* `loop` no longer replaces string literals equal to "recur"
|
* `loop` no longer replaces string literals equal to "recur"
|
||||||
* The REPL now prints the correct value of `do` and `try` forms
|
* 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 ]
|
[ Misc. Improvements ]
|
||||||
* New contrib module `hy-repr`
|
* New contrib module `hy-repr`
|
||||||
|
@ -34,7 +34,7 @@ def tokenize(buf):
|
|||||||
except LexingError as e:
|
except LexingError as e:
|
||||||
pos = e.getsourcepos()
|
pos = e.getsourcepos()
|
||||||
raise LexException("Could not identify the next token.",
|
raise LexException("Could not identify the next token.",
|
||||||
pos.lineno, pos.colno)
|
pos.lineno, pos.colno, buf)
|
||||||
except LexException as e:
|
except LexException as e:
|
||||||
if e.source is None:
|
if e.source is None:
|
||||||
e.source = buf
|
e.source = buf
|
||||||
|
@ -24,12 +24,12 @@ from hy.errors import HyError
|
|||||||
|
|
||||||
class LexException(HyError):
|
class LexException(HyError):
|
||||||
"""Error during the Lexing of a Hython expression."""
|
"""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)
|
super(LexException, self).__init__(message)
|
||||||
self.message = message
|
self.message = message
|
||||||
self.lineno = lineno
|
self.lineno = lineno
|
||||||
self.colno = colno
|
self.colno = colno
|
||||||
self.source = None
|
self.source = source
|
||||||
self.filename = '<stdin>'
|
self.filename = '<stdin>'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -63,6 +63,17 @@ def test_unbalanced_exception():
|
|||||||
pass
|
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():
|
def test_lex_expression_symbols():
|
||||||
""" Make sure that expressions produce symbols """
|
""" Make sure that expressions produce symbols """
|
||||||
objs = tokenize("(foo bar)")
|
objs = tokenize("(foo bar)")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user