Przeglądaj źródła

Don't compile unused terminals (mentioned in issue #309)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Erez Shinan 5 lat temu
rodzic
commit
145d8a8e7c
1 zmienionych plików z 7 dodań i 2 usunięć
  1. +7
    -2
      lark/load_grammar.py

+ 7
- 2
lark/load_grammar.py Wyświetl plik

@@ -521,6 +521,13 @@ class Grammar:
rule = Rule(NonTerminal(name), expansion, i, alias, exp_options)
compiled_rules.append(rule)


# Filter out unused terminals
used_terms = {t.name for r in compiled_rules
for t in r.expansion
if isinstance(t, Terminal)}
terminals = [t for t in terminals if t.name in used_terms or t.name in self.ignore]

return terminals, compiled_rules, self.ignore


@@ -794,8 +801,6 @@ class GrammarLoader:
if sym not in rule_names:
raise GrammarError("Rule '%s' used but not defined (in rule %s)" % (sym, name))

# TODO don't include unused terminals, they can only cause trouble!

return Grammar(rules, term_defs, ignore_names)




Ładowanie…
Anuluj
Zapisz