Browse Source

Refactored the Earley code to make it thread-safe (Issue #454)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.7
Erez Sh 5 years ago
parent
commit
94da6c52b8
1 changed files with 5 additions and 6 deletions
  1. +5
    -6
      lark/parsers/earley.py

+ 5
- 6
lark/parsers/earley.py View File

@@ -46,12 +46,8 @@ class Parser:
# skip the extra tree walk. We'll also skip this if the user just didn't specify priorities
# on any rules.
if self.forest_sum_visitor is None and rule.options and rule.options.priority is not None:
self.forest_sum_visitor = ForestSumVisitor()
self.forest_sum_visitor = ForestSumVisitor

if resolve_ambiguity:
self.forest_tree_visitor = ForestToTreeVisitor(self.callbacks, self.forest_sum_visitor)
else:
self.forest_tree_visitor = ForestToAmbiguousTreeVisitor(self.callbacks, self.forest_sum_visitor)
self.term_matcher = term_matcher


@@ -316,7 +312,10 @@ class Parser:
assert False, 'Earley should not generate multiple start symbol items!'

# Perform our SPPF -> AST conversion using the right ForestVisitor.
return self.forest_tree_visitor.visit(solutions[0])
forest_tree_visitor_cls = ForestToTreeVisitor if self.resolve_ambiguity else ForestToAmbiguousTreeVisitor
forest_tree_visitor = forest_tree_visitor_cls(self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor())

return forest_tree_visitor.visit(solutions[0])


class ApplyCallbacks(Transformer_InPlace):


Loading…
Cancel
Save