Skip to content

Fix Template.search() dropping zero-variable matches - #1632

Open
Sanjays2402 wants to merge 1 commit into
lark-parser:masterfrom
Sanjays2402:fix/template-search-zero-variable-matches
Open

Fix Template.search() dropping zero-variable matches#1632
Sanjays2402 wants to merge 1 commit into
lark-parser:masterfrom
Sanjays2402:fix/template-search-zero-variable-matches

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #1630

Template.match() returns {} for a match with no variables to bind and None for no match, but search() tested the result for truthiness — so {} was read as "no match" and every zero-variable match was dropped, leaving translate() a no-op for variable-free templates. search() now tests res is not None.

The two existing search tests asserted the broken empty result and are corrected; added a test that a genuinely different tree still yields nothing, plus a TemplateTranslator case for a variable-free translation. The three tests fail on master and pass with the fix; full suite is 1134 passed / 174 skipped.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

Template.match() returns an empty dict when a template with no variable
placeholders matches a subtree, and None when there is no match. search()
tested the result for truthiness, so the empty dict was treated as "no
match" and every zero-variable match was silently dropped. translate()
therefore never replaced anything for such templates.

search() now tests `res is not None`, matching the contract match()
documents.

Two existing search tests asserted the broken behaviour and are corrected;
added a test that a genuinely different tree still yields nothing, and a
TemplateTranslator test covering a variable-free translation.

Closes lark-parser#1630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Template.search() to yield zero-variable matches

1 participant