Explorar el Código

Fixed a bug in string evaluation

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan hace 7 años
padre
commit
d8cbd239d7
Se han modificado 3 ficheros con 12 adiciones y 2 borrados
  1. +1
    -1
      examples/reconstruct_json.py
  2. +2
    -1
      lark/load_grammar.py
  3. +9
    -0
      tests/test_parser.py

+ 1
- 1
examples/reconstruct_json.py Ver fichero

@@ -46,7 +46,7 @@ def test_lalr():

new_json = Reconstructor(json_parser).reconstruct(tree)
print (new_json)
print (json.loads(new_json) == json.loads(test_json))
print (json.loads(new_json) == json.loads(test_json))

test_scanless()
test_lalr()

+ 2
- 1
lark/load_grammar.py Ver fichero

@@ -290,7 +290,8 @@ class ExtractAnonTokens(InlineTransformer):
def _literal_to_pattern(literal):
v = literal.value
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,
'REGEXP': PatternRE }[literal.type](s)



+ 9
- 0
tests/test_parser.py Ver fichero

@@ -407,6 +407,15 @@ def _make_parser_test(LEXER, PARSER):
""")
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):
g = _Lark(r"""start: "\"" "-"


Cargando…
Cancelar
Guardar