Selaa lähdekoodia

Merge pull request #922 from ornariece/master

Fix #696 now providing the correct amount of placeholders
remotes/origin/gm/2021-09-23T00Z/github.com--lark-parser-lark/master
Erez Shinan 3 vuotta sitten
committed by GitHub
vanhempi
commit
a12effe913
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 muutettua tiedostoa jossa 13 lisäystä ja 5 poistoa
  1. +4
    -5
      lark/load_grammar.py
  2. +9
    -0
      tests/test_parser.py

+ 4
- 5
lark/load_grammar.py Näytä tiedosto

@@ -345,12 +345,11 @@ class EBNF_to_BNF(Transformer_InPlace):
return not sym.name.startswith('_')
if isinstance(sym, Terminal):
return keep_all_tokens or not sym.filter_out
assert False
if sym is _EMPTY:
return False
assert False, sym

if any(rule.scan_values(will_not_get_removed)):
empty = _EMPTY
else:
empty = ST('expansion', [])
empty = ST('expansion', [_EMPTY] * len(list(rule.scan_values(will_not_get_removed))))

return ST('expansions', [rule, empty])



+ 9
- 0
tests/test_parser.py Näytä tiedosto

@@ -2292,6 +2292,15 @@ def _make_parser_test(LEXER, PARSER):
self.assertEqual(p.parse("abba").children, ['a', None, 'b', 'b', 'a', None])
self.assertEqual(p.parse("cbbbb").children, [None, 'c', 'b', 'b', 'b', 'b', None, None])

p = _Lark("""!start: ["a" "b" "c"] """, maybe_placeholders=True)
self.assertEqual(p.parse("").children, [None, None, None])
self.assertEqual(p.parse("abc").children, ['a', 'b', 'c'])

p = _Lark("""!start: ["a" ["b" "c"]] """, maybe_placeholders=True)
self.assertEqual(p.parse("").children, [None, None, None])
self.assertEqual(p.parse("a").children, ['a', None, None])
self.assertEqual(p.parse("abc").children, ['a', 'b', 'c'])


def test_escaped_string(self):
"Tests common.ESCAPED_STRING"


Ladataan…
Peruuta
Tallenna