Procházet zdrojové kódy

Raise a GrammarError on empty string literal.

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.12.0
MegaIng před 3 roky
rodič
revize
c44bb3e0cd
2 změnil soubory, kde provedl 7 přidání a 0 odebrání
  1. +3
    -0
      lark/load_grammar.py
  2. +4
    -0
      tests/test_grammar.py

+ 3
- 0
lark/load_grammar.py Zobrazit soubor

@@ -448,6 +448,9 @@ def _literal_to_pattern(literal):

s = eval_escaping(x)

if s == "":
raise GrammarError("Can't have empty terminals (offending literal: %s)" % literal.value)

if literal.type == 'STRING':
s = s.replace('\\\\', '\\')
return PatternStr(s, flags, raw=literal.value)


+ 4
- 0
tests/test_grammar.py Zobrazit soubor

@@ -22,6 +22,10 @@ class TestGrammar(TestCase):
else:
assert False, "example did not raise an error"

def test_empty_literal(self):
# Issues #888
self.assertRaises(GrammarError, Lark, "start: \"\"")

def test_override_rule(self):
# Overrides the 'sep' template in existing grammar to add an optional terminating delimiter
# Thus extending it beyond its original capacity


Načítá se…
Zrušit
Uložit