diff --git a/lark/parsers/earley.py b/lark/parsers/earley.py index d09732e7..8ac7ecbe 100644 --- a/lark/parsers/earley.py +++ b/lark/parsers/earley.py @@ -286,6 +286,9 @@ def parse(self, lexer, start): if not solutions: expected_terminals = [t.expect.name for t in to_scan] raise UnexpectedEOF(expected_terminals, state=frozenset(i.s for i in to_scan)) + if len(solutions) > 1: + raise RuntimeError('Earley should not generate multiple start symbol items! Please report this bug.') + solution ,= solutions if self.debug: from .earley_forest import ForestToPyDotVisitor @@ -294,10 +297,8 @@ def parse(self, lexer, start): except ImportError: logger.warning("Cannot find dependency 'pydot', will not generate sppf debug image") else: - debug_walker.visit(solutions[0], "sppf.png") + debug_walker.visit(solution, "sppf.png") - if len(solutions) > 1: - assert False, 'Earley should not generate multiple start symbol items!' if self.Tree is not None: # Perform our SPPF -> AST conversion @@ -305,7 +306,7 @@ def parse(self, lexer, start): # to prevent a tree construction bug. See issue #1283 use_cache = not self.resolve_ambiguity transformer = ForestToParseTree(self.Tree, self.callbacks, self.forest_sum_visitor and self.forest_sum_visitor(), self.resolve_ambiguity, use_cache) - return transformer.transform(solutions[0]) + return transformer.transform(solution) # return the root of the SPPF - return solutions[0] + return solution diff --git a/lark/utils.py b/lark/utils.py index 3767a66d..2d33f693 100644 --- a/lark/utils.py +++ b/lark/utils.py @@ -184,7 +184,7 @@ def is_id_start(s: str) -> bool: return _test_unicode_category(s, _ID_START) -def dedup_list(l: Sequence[T]) -> List[T]: +def dedup_list(l: Iterable[T]) -> List[T]: """Given a list (l) will removing duplicates from the list, preserving the original order of the list. Assumes that the list entries are hashable."""