Skip to content

Commit

Permalink
Bugfix for issue #1434
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Jun 30, 2024
1 parent 5016894 commit 2f6aaa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lark/parsers/grammar_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import Counter, defaultdict
from typing import List, Dict, Iterator, FrozenSet, Set

from ..utils import bfs, fzset, classify
from ..utils import bfs, fzset, classify, OrderedSet
from ..exceptions import GrammarError
from ..grammar import Rule, Terminal, NonTerminal, Symbol
from ..common import ParserConf
Expand Down Expand Up @@ -177,13 +177,13 @@ def __init__(self, parser_conf: ParserConf, debug: bool=False, strict: bool=Fals

self.FIRST, self.FOLLOW, self.NULLABLE = calculate_sets(rules)

def expand_rule(self, source_rule: NonTerminal, rules_by_origin=None) -> State:
def expand_rule(self, source_rule: NonTerminal, rules_by_origin=None) -> OrderedSet[RulePtr]:
"Returns all init_ptrs accessible by rule (recursive)"

if rules_by_origin is None:
rules_by_origin = self.rules_by_origin

init_ptrs = set()
init_ptrs = OrderedSet[RulePtr]()
def _expand_rule(rule: NonTerminal) -> Iterator[NonTerminal]:
assert not rule.is_term, rule

Expand All @@ -200,4 +200,4 @@ def _expand_rule(rule: NonTerminal) -> Iterator[NonTerminal]:
for _ in bfs([source_rule], _expand_rule):
pass

return fzset(init_ptrs)
return init_ptrs
3 changes: 3 additions & 0 deletions lark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,6 @@ def __bool__(self):

def __len__(self) -> int:
return len(self.d)

def __repr__(self):
return f"{type(self).__name__}({', '.join(map(str,self))})"

0 comments on commit 2f6aaa6

Please sign in to comment.