From e478008cceab11255bfabcf99129730e827672b9 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Fri, 24 Mar 2017 11:09:30 -0700 Subject: [PATCH] Fix HyMacroExpansionError underline alignment --- hy/cmdline.py | 6 ++++-- tests/test_bin.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hy/cmdline.py b/hy/cmdline.py index 699e5f6..beb84f7 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -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: diff --git a/tests/test_bin.py b/tests/test_bin.py index bc32749..b355e63 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -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', '')