Przeglądaj źródła

Better error message for reduce/reduce conflict (Issue #135)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.0
Erez Sh 4 lat temu
rodzic
commit
fcdba441b4
2 zmienionych plików z 3 dodań i 2 usunięć
  1. +1
    -0
      lark/load_grammar.py
  2. +2
    -2
      lark/parsers/lalr_analysis.py

+ 1
- 0
lark/load_grammar.py Wyświetl plik

@@ -478,6 +478,7 @@ class Grammar:
rules = []
for name, rule_tree, options in rule_defs:
ebnf_to_bnf.rule_options = RuleOptions(keep_all_tokens=True) if options.keep_all_tokens else None
ebnf_to_bnf.prefix = name
tree = transformer.transform(rule_tree)
res = ebnf_to_bnf.transform(tree)
rules.append((name, res, options))


+ 2
- 2
lark/parsers/lalr_analysis.py Wyświetl plik

@@ -253,10 +253,10 @@ class LALR_Analyzer(GrammarAnalyzer):
actions[la] = (Shift, next_state.closure)
for la, rules in state.lookaheads.items():
if len(rules) > 1:
raise GrammarError('Collision in %s: %s' % (la, ', '.join([ str(r) for r in rules ])))
raise GrammarError('Reduce/Reduce collision in %s between the following rules: %s' % (la, ''.join([ '\n\t\t- ' + str(r) for r in rules ])))
if la in actions:
if self.debug:
logging.warning('Shift/reduce conflict for terminal %s: (resolving as shift)', la.name)
logging.warning('Shift/Reduce conflict for terminal %s: (resolving as shift)', la.name)
logging.warning(' * %s', list(rules)[0])
else:
actions[la] = (Reduce, list(rules)[0])


Ładowanie…
Anuluj
Zapisz