Browse Source

Need to remove duplicate rules for root rools as well.

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
julienmalard 4 years ago
parent
commit
a3368d8a72
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      lark/reconstruct.py

+ 7
- 1
lark/reconstruct.py View File

@@ -1,3 +1,4 @@
import unicodedata
from collections import defaultdict

from .tree import Tree
@@ -166,7 +167,12 @@ class Reconstructor:
try:
parser = self._parser_cache[tree.data]
except KeyError:
rules = self.rules + self.rules_for_root[tree.data]
rules = self.rules + best_from_group(
self.rules_for_root[tree.data], lambda r: r, lambda r: -len(r.expansion)
)

rules.sort(key=lambda r: len(r.expansion))

callbacks = {rule: rule.alias for rule in rules} # TODO pass callbacks through dict, instead of alias?
parser = earley.Parser(ParserConf(rules, callbacks, [tree.data]), self._match, resolve_ambiguity=True)
self._parser_cache[tree.data] = parser


Loading…
Cancel
Save