diff --git a/examples/python3.g b/examples/python3.g index 279c268..a382d0b 100644 --- a/examples/python3.g +++ b/examples/python3.g @@ -116,11 +116,12 @@ AWAIT: "await" | atom_expr "." NAME -> getattr | atom -?atom: "(" [yield_expr|testlist_comp] ")" - | "[" [testlist_comp] "]" - | "{" [dictorsetmaker] "}" +?atom: "(" [yield_expr|testlist_comp] ")" -> tuple + | "[" [testlist_comp] "]" -> list + | "{" [dictorsetmaker] "}" -> dict | NAME -> var - | number | string+ | "..." + | number | string+ + | "..." -> ellipsis | "None" -> const_none | "True" -> const_true | "False" -> const_false diff --git a/lark/parsers/earley.py b/lark/parsers/earley.py index dfe13c7..6014fee 100644 --- a/lark/parsers/earley.py +++ b/lark/parsers/earley.py @@ -107,7 +107,7 @@ class Column: new_tree.rule = old_tree.rule old_tree.set('_ambig', [new_tree]) if item.tree.children[0] is old_tree: # XXX a little hacky! - raise ParseError("Infinite recursion in grammar!") + raise ParseError("Infinite recursion in grammar! (Rule %s)" % item.rule) old_tree.children.append(item.tree) else: self.completed[item] = item @@ -228,6 +228,12 @@ def _compare_drv(tree1, tree2): if not (isinstance(tree1, Tree) and isinstance(tree2, Tree)): return compare(tree1, tree2) + try: + rule1, rule2 = tree1.rule, tree2.rule + except AttributeError: + # Probably trees that don't take part in this parse (better way to distinguish?) + return compare(tree1, tree2) + c = _compare_rules(tree1.rule, tree2.rule) if c: return c