Sfoglia il codice sorgente

Bugfix and warn on ambiguous intermediate nodes, based on PR #651

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
Erez Sh 4 anni fa
parent
commit
39fb4c0f3e
1 ha cambiato i file con 12 aggiunte e 4 eliminazioni
  1. +12
    -4
      lark/parsers/earley_forest.py

+ 12
- 4
lark/parsers/earley_forest.py Vedi File

@@ -13,6 +13,7 @@ from collections import deque
from operator import attrgetter
from importlib import import_module

from ..utils import logger
from ..tree import Tree
from ..exceptions import ParseError

@@ -328,10 +329,17 @@ class ForestToAmbiguousTreeVisitor(ForestToTreeVisitor):
self.output_stack[-1].children.append(node)

def visit_symbol_node_in(self, node):
if self.forest_sum_visitor and node.is_ambiguous and isinf(node.priority):
self.forest_sum_visitor.visit(node)
if not node.is_intermediate and node.is_ambiguous:
self.output_stack.append(Tree('_ambig', []))
if node.is_ambiguous:
if self.forest_sum_visitor and isinf(node.priority):
self.forest_sum_visitor.visit(node)
if node.is_intermediate:
# TODO Support ambiguous intermediate nodes!
logger.warning("Ambiguous intermediate node in the SPPF: %s. "
"Lark does not currently process these ambiguities; resolving with the first derivation.", node)
return next(iter(node.children))
else:
self.output_stack.append(Tree('_ambig', []))

return iter(node.children)

def visit_symbol_node_out(self, node):


Caricamento…
Annulla
Salva