Browse Source

Merge pull request #365 from PJCampi/bugfix/364-reconstruction-update-start-symbol-of-parser-instead-of-recreating-it

Bugfix/364 reconstruction update start symbol of parser instead of recreating it
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.1
Erez Shinan 6 years ago
committed by GitHub
parent
commit
e2c87369c0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      lark/reconstruct.py

+ 4
- 3
lark/reconstruct.py View File

@@ -73,6 +73,9 @@ class Reconstructor:


self.write_tokens = WriteTokensTransformer({t.name:t for t in tokens}) self.write_tokens = WriteTokensTransformer({t.name:t for t in tokens})
self.rules = list(self._build_recons_rules(rules)) self.rules = list(self._build_recons_rules(rules))
callbacks = {rule: rule.alias for rule in self.rules} # TODO pass callbacks through dict, instead of alias?
self.parser = earley.Parser(ParserConf(self.rules, callbacks, parser.options.start),
self._match, resolve_ambiguity=True)


def _build_recons_rules(self, rules): def _build_recons_rules(self, rules):
expand1s = {r.origin for r in rules if r.options and r.options.expand1} expand1s = {r.origin for r in rules if r.options and r.options.expand1}
@@ -112,9 +115,7 @@ class Reconstructor:


def _reconstruct(self, tree): def _reconstruct(self, tree):
# TODO: ambiguity? # TODO: ambiguity?
callbacks = {rule: rule.alias for rule in self.rules} # TODO pass callbacks through dict, instead of alias?
parser = earley.Parser(ParserConf(self.rules, callbacks, tree.data), self._match, resolve_ambiguity=True)
unreduced_tree = parser.parse(tree.children) # find a full derivation
unreduced_tree = self.parser.parse(tree.children, tree.data) # find a full derivation
assert unreduced_tree.data == tree.data assert unreduced_tree.data == tree.data
res = self.write_tokens.transform(unreduced_tree) res = self.write_tokens.transform(unreduced_tree)
for item in res: for item in res:


Loading…
Cancel
Save