diff --git a/hy/lex/states.py b/hy/lex/states.py index cdf785f..6966a39 100644 --- a/hy/lex/states.py +++ b/hy/lex/states.py @@ -233,7 +233,11 @@ class String(State): if char == "n": self.nodes.append("\n") return - raise LexException("Unknown modifier") + if char == "\\": + self.nodes.append("\\") + return + + raise LexException("Unknown modifier: `%s'" % (char)) if char == "\"": return Idle diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 3350667..fafcbcf 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -89,15 +89,15 @@ def test_ast_non_kwapplyable(): def test_ast_print(): - """ Ensure print doesn't suck. """ code = hy_compile(tokenize("(print \"foo\")")).body[0] + if sys.version_info[0] >= 3: assert type(code.value) == ast.Call return assert type(code) == ast.Print -def test_ast_print(): - """ Ensure print doesn't suck. """ +def test_ast_tuple(): + """ Ensure tuples work. """ code = hy_compile(tokenize("(, 1 2 3)")).body[0].value assert type(code) == ast.Tuple diff --git a/tests/lex/test_lex.py b/tests/lex/test_lex.py index 1eb6180..7740fed 100644 --- a/tests/lex/test_lex.py +++ b/tests/lex/test_lex.py @@ -148,3 +148,21 @@ def test_nospace(): assert entry.end_line == 1 assert entry.end_column == 13 + + +def test_escapes(): + """ Ensure we can escape things """ + entry = tokenize("(foo \"foo\\n\")")[0] + assert entry[1] == "foo\n" + + try: + entry = tokenize("(foo \"foo\s\")")[0] + assert True is False + except LexException: + pass + + +def test_hashbang(): + """ Ensure we can escape things """ + entry = tokenize("#!this is a comment\n") + assert entry == []