Fix lexer_callbacks silently dropped for keyword terminals (#1618)#1619
Open
apoorvdarshan wants to merge 1 commit into
Open
Fix lexer_callbacks silently dropped for keyword terminals (#1618)#1619apoorvdarshan wants to merge 1 commit into
apoorvdarshan wants to merge 1 commit into
Conversation
When two or more terminals each absorb a same-priority keyword (producing an UnlessCallback) and also have a lexer_callbacks entry, every user callback except the last silently never fired. BasicLexer built each CallChain with 'lambda t: t.type == type_', which closes over the loop variable, so all conditions ended up comparing against the last terminal's name. Bind type_ per iteration. Fixes lark-parser#1618.
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.
Summary
Fixes #1618. When two or more terminals each absorb a same-priority keyword literal (so they get an
UnlessCallback) and have alexer_callbacksentry, every user callback except the last silently never fires.Root cause
BasicLexerchains an existingUnlessCallbackwith the user callback:The
lambda t: t.type == type_closes over the loop variabletype_, so after the loop everyCallChaincondition compares against the last terminal's name. For all but the last terminal the condition is never true, so the user callback is skipped.Fix
Bind
type_per iteration via a default argument (lambda t, type_=type_: ...).Verification
TestGrammar.test_lexer_callbacks_with_keyword_terminals; it fails onmaster(only the last callback fires) and passes here.UnlessCallbackcontinues to convertfoo/123toAKW/BKW, which correctly do not trigger theA/Bcallbacks).