Bugfix: call __default_token__ from an embedded transformer (Issue #1582)#1612
Open
Labib-Bin-Salam wants to merge 1 commit into
Open
Bugfix: call __default_token__ from an embedded transformer (Issue #1582)#1612Labib-Bin-Salam wants to merge 1 commit into
Labib-Bin-Salam wants to merge 1 commit into
Conversation
…rk-parser#1582) When a transformer is applied during parsing via Lark(transformer=...), tokens without a dedicated method were left untouched, whereas Transformer.transform() falls back to __default_token__ for them. _get_lexer_callbacks now wires up an overridden __default_token__ as the fallback token callback, matching transform(). The base no-op is skipped, so the common case keeps tokens untouched with no extra call per token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1582.
Transformer.__default_token__is called for tokens without a dedicated method when runningtransformer.transform(tree), but it was never invoked by the embedded transformer (Lark(transformer=...)). As confirmed by @erezsh in the issue,__default_token__"was never implemented for the internal transformer"._get_lexer_callbacksonly registered a token callback when the transformer defined a method named after the terminal. It now falls back to an overridden__default_token__for the remaining terminals, mirroringTransformer.transform(). The base no-op implementation is skipped, so transformers that don't override__default_token__keep the existing fast path (no extra call per token), and specific token methods still take precedence.Example
Notes
test_default_token_in_treeless_mode) asserting the embedded transformer matchestransform().lalrparser, the only one that applies embedded token callbacks. Thecykparser does not apply embedded token callbacks at all (not even specific token methods) — a separate, pre-existing limitation.python -m testspasses (1283 tests) andmypyis clean.