| @@ -46,7 +46,7 @@ def test_lalr(): | |||||
| new_json = Reconstructor(json_parser).reconstruct(tree) | new_json = Reconstructor(json_parser).reconstruct(tree) | ||||
| print (new_json) | print (new_json) | ||||
| print (json.loads(new_json) == json.loads(test_json)) | |||||
| print (json.loads(new_json) == json.loads(test_json)) | |||||
| test_scanless() | test_scanless() | ||||
| test_lalr() | test_lalr() | ||||
| @@ -290,7 +290,8 @@ class ExtractAnonTokens(InlineTransformer): | |||||
| def _literal_to_pattern(literal): | def _literal_to_pattern(literal): | ||||
| v = literal.value | v = literal.value | ||||
| assert v[0] == v[-1] and v[0] in '"/' | assert v[0] == v[-1] and v[0] in '"/' | ||||
| s = literal_eval("u'''%s'''" % v[1:-1]) | |||||
| x = v[1:-1].replace("'", r"\'") | |||||
| s = literal_eval("u'''%s'''" % x) | |||||
| return { 'STRING': PatternStr, | return { 'STRING': PatternStr, | ||||
| 'REGEXP': PatternRE }[literal.type](s) | 'REGEXP': PatternRE }[literal.type](s) | ||||
| @@ -407,6 +407,15 @@ def _make_parser_test(LEXER, PARSER): | |||||
| """) | """) | ||||
| x = g.parse(r'\a') | x = g.parse(r'\a') | ||||
| def test_special_chars(self): | |||||
| g = _Lark(r"""start: "\n" | |||||
| """) | |||||
| x = g.parse('\n') | |||||
| g = _Lark(r"""start: /\n/ | |||||
| """) | |||||
| x = g.parse('\n') | |||||
| def test_backslash2(self): | def test_backslash2(self): | ||||
| g = _Lark(r"""start: "\"" "-" | g = _Lark(r"""start: "\"" "-" | ||||