Whole file

lark-parser/lark

The author described this change as BUGFIX: Fixes a subtle bug in the LALR(1) parser. See the new test for details.. It counts as a record because the checks below fail on the code as it stood at e20b54be2 and pass on 64d141e48, with nothing else changed between the two runs.

Fix saved2017-05-22
Sharing licenceMIT · LICENSE
Change size+3 3

What the code was meant to do, written into the code itself as a save note

BUGFIX: Fixes a subtle bug in the LALR(1) parser. See the new test for details.

The change

3434
3535 raise UnexpectedToken(token, expected, seq, i)
3636
37- def reduce(rule, size):
37+ def reduce(rule, size, end=False):
3838 if size:
3939 s = value_stack[-size:]
4040 del state_stack[-size:]
4444
4545 res = self.callbacks[rule](s)
4646
47- if len(state_stack) == 1 and rule.origin == self.analysis.start_symbol:
47+ if end and len(state_stack) == 1 and rule.origin == self.analysis.start_symbol:
4848 return res
4949
5050 _action, new_state = get_action(rule.origin)
7373 while True:
7474 _action, rule = get_action('$end')
7575 assert _action == 'reduce'
76- res = reduce(*rule)
76+ res = reduce(*rule, end=True)
7777 if res:
7878 assert state_stack == [self.analysis.init_state_idx] and not value_stack, len(state_stack)
7979 return res

The check that tells the two apart

failpass·tests/test_parser.py::TestLalrContextual::test_reduce_cycle
failpass·tests/test_parser.py::TestLalrStandard::test_reduce_cycle

Check file tests/test_parser.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before ite20b54be2fa9e6594a10bdd9cc8c36a3ffe46bc0
Broken version dated2017-05-06
Modulelark.parsers.lalr_parser
Units changedParser
Fingerprint3b575f8fce448ac4
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in lark-parser/lark