Ver a proveniência

BUGFIX: Mishandling of quotes (Issue #50)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan há 6 anos
ascendente
cometimento
209ac5ab4e
2 ficheiros alterados com 14 adições e 1 eliminações
  1. +1
    -1
      lark/load_grammar.py
  2. +13
    -0
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py Ver ficheiro

@@ -293,7 +293,6 @@ def _rfind(s, choices):


def _fix_escaping(s):
s = s.replace('\\"', '"').replace("'", "\\'")
w = ''
i = iter(s)
for n in i:
@@ -305,6 +304,7 @@ def _fix_escaping(s):
elif n2 not in 'unftr':
w += '\\'
w += n2
w = w.replace('\\"', '"').replace("'", "\\'")

to_eval = "u'''%s'''" % w
try:


+ 13
- 0
tests/test_parser.py Ver ficheiro

@@ -711,6 +711,19 @@ def _make_parser_test(LEXER, PARSER):
""")
x = g.parse('AB')

@unittest.skipIf(LEXER == None, "Scanless can't handle regexps")
def test_regex_quote(self):
g = r"""
start: SINGLE_QUOTED_STRING | DOUBLE_QUOTED_STRING
SINGLE_QUOTED_STRING : /'[^']*'/
DOUBLE_QUOTED_STRING : /"[^"]*"/
"""

g = _Lark(g)
self.assertEqual( g.parse('"hello"').children, ['"hello"'])
self.assertEqual( g.parse("'hello'").children, ["'hello'"])


def test_lexer_token_limit(self):
"Python has a stupid limit of 100 groups in a regular expression. Test that we handle this limitation"
tokens = {'A%d'%i:'"%d"'%i for i in range(300)}


Carregando…
Cancelar
Guardar