Browse Source

BUGFIX: Mishandling of quotes (Issue #50)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
209ac5ab4e
2 changed files with 14 additions and 1 deletions
  1. +1
    -1
      lark/load_grammar.py
  2. +13
    -0
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py View File

@@ -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 View File

@@ -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)}


Loading…
Cancel
Save