Skip to content

Commit

Permalink
Disable ForestToParseTree cache when ambiguity='resolve' (issue lark-…
Browse files Browse the repository at this point in the history
  • Loading branch information
chanicpanic committed Jun 28, 2024
1 parent 00d83f9 commit 50a8a14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lark/parsers/earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def parse(self, lexer, start):

if self.Tree is not None:
# Perform our SPPF -> AST conversion
transformer = ForestToParseTree(self.Tree, self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor(), self.resolve_ambiguity)
transformer = ForestToParseTree(self.Tree, self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor(), self.resolve_ambiguity, not self.resolve_ambiguity)
solutions = [transformer.transform(s) for s in solutions]

if len(solutions) > 1:
Expand Down
7 changes: 4 additions & 3 deletions lark/parsers/earley_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,10 @@ def transform_packed_node(self, node, data):
children.append(data.left)
if data.right is not PackedData.NO_DATA:
children.append(data.right)
if node.parent.is_intermediate:
return self._cache.setdefault(id(node), children)
return self._cache.setdefault(id(node), self._call_rule_func(node, children))
transformed = children if node.parent.is_intermediate else self._call_rule_func(node, children)
if self._use_cache:
self._cache[id(node)] = transformed
return transformed

def visit_symbol_node_in(self, node):
super(ForestToParseTree, self).visit_symbol_node_in(node)
Expand Down

0 comments on commit 50a8a14

Please sign in to comment.