One function
Transformer_NonRecursive in lark-parser/lark
The author described this change as “Transformer_NonRecursive should respond as documented to a Discard exception being raised”. It counts as a record because the check below fails on the code as it stood at 1f56497de and passes on 50e789ab9, with nothing else changed between the two runs.
Projectlark-parser/lark
Fix saved2021-10-04
Sharing licenceMIT · LICENSE
Change size+8 −2
What the code was meant to do, written into the code itself as a docstring
Same as Transformer but non-recursive. Like Transformer, it doesn't change the original tree. Useful for huge trees.
The change
| 26 | 26 | del stack[-size:] | |
| 27 | 27 | else: | |
| 28 | 28 | args = [] | |
| 29 | - | stack.append(self._call_userfunc(x, args)) | |
| 29 | + | try: | |
| 30 | + | stack.append(self._call_userfunc(x, args)) | |
| 31 | + | except Discard: | |
| 32 | + | pass | |
| 30 | 33 | elif self.__visit_tokens__ and isinstance(x, Token): | |
| 31 | - | stack.append(self._call_userfunc_token(x)) | |
| 34 | + | try: | |
| 35 | + | stack.append(self._call_userfunc_token(x)) | |
| 36 | + | except Discard: | |
| 37 | + | pass | |
| 32 | 38 | else: | |
| 33 | 39 | stack.append(x) | |
| 34 | 40 |
The check that tells the two apart
fail→pass·tests/test_trees.py::TestTrees::test_transformer_variants
Check file tests/test_trees.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 it1f56497de8d90c6136dcda0ce71f4de3b298a07e
Broken version dated2021-09-24
Modulelark.visitors
Units changedTransformer_NonRecursive
Fingerprint6a8a9b799ac862e3
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
- 2026-07-08Fix lexer_callbacks silently dropped for keyword terminals
- 2026-06-24Transformer_NonRecursive
- 2026-06-04Raise GrammarError for non-terminal names in %declare
- 2026-06-02Fix empty SPPF node from xearley ignore carry-over (fixes #1598)
- 2026-05-24fix: raise GrammarError for template usage inside terminals
- 2024-10-25Adjust behaviour in #1481 to raise a NotImplementedError