Pārlūkot izejas kodu

BUGFIX: Mishandling of quotes (Issue #50)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan pirms 6 gadiem
vecāks
revīzija
209ac5ab4e
2 mainītis faili ar 14 papildinājumiem un 1 dzēšanām
  1. +1
    -1
      lark/load_grammar.py
  2. +13
    -0
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py Parādīt failu

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




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


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


+ 13
- 0
tests/test_parser.py Parādīt failu

@@ -711,6 +711,19 @@ def _make_parser_test(LEXER, PARSER):
""") """)
x = g.parse('AB') 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): def test_lexer_token_limit(self):
"Python has a stupid limit of 100 groups in a regular expression. Test that we handle this limitation" "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)} tokens = {'A%d'%i:'"%d"'%i for i in range(300)}


Notiek ielāde…
Atcelt
Saglabāt