Fix HyMacroExpansionError underline alignment

This commit is contained in:
Kodi Arfer 2017-03-24 11:09:30 -07:00
parent ca1bd0ffd3
commit e478008cce
2 changed files with 9 additions and 2 deletions

View File

@ -103,7 +103,9 @@ class HyREPL(code.InteractiveConsole):
tokens = tokenize(source)
except PrematureEndOfInput:
return True
tokens = tokenize("(do " + source + "\n)")
do = HyExpression([HySymbol('do')] + tokens)
do.start_line = do.end_line = do.start_column = do.end_column = 1
do.replace(do)
except LexException as e:
if e.source is None:
e.source = source
@ -119,7 +121,7 @@ class HyREPL(code.InteractiveConsole):
new_ast = ast.Module(main_ast.body +
[ast.Expr(expr_ast.body)])
print(astor.to_source(new_ast))
value = hy_eval(tokens[0], self.locals, "__console__",
value = hy_eval(do, self.locals, "__console__",
ast_callback)
except HyTypeError as e:
if e.source is None:

View File

@ -109,6 +109,11 @@ def test_bin_hy_stdin_as_arrow():
assert re.match(r"=>\s+2L?\s+=>", output)
def test_bin_hy_stdin_error_underline_alignment():
_, err = run_cmd("hy", "(defmacro mabcdefghi [x] x)\n(mabcdefghi)")
assert "\n (mabcdefghi)\n ^----------^" in err
def test_bin_hy_stdin_hy_repr():
output, _ = run_cmd("hy", '(+ [1] [2])')
assert "[1, 2]" in output.replace('L', '')