Fix Template.search() dropping zero-variable matches 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 #1630
Recent Commits to lark:master
-
Fix Template.search() dropping zero-variable matches
-
Merge pull request #1605 from nchammas/indenter-docs
Merge pull request #1605 from nchammas/indenter-docs Show Indenter property docs + add working links
-
Support backslash line continuations in lark.lark
Support backslash line continuations in lark.lark The lark.lark meta-grammar did not accept backslash-newline line continuations, even though grammars parsed by lark support them. Add a BACKSLASH terminal and ignore it, plus a regression test.
-
Extract Python comprehension filters rule
Extract Python comprehension filters rule
-
Merge pull request #1614 from gaoflow/fix-transformer-nonrecursive-di…
Merge pull request #1614 from gaoflow/fix-transformer-nonrecursive-discard-root Fix Transformer_NonRecursive crashing when root node is discarded
-
Merge pull request #1619 from apoorvdarshan/fix-1618-lexer-callback-c…
Merge pull request #1619 from apoorvdarshan/fix-1618-lexer-callback-closure Fix lexer_callbacks silently dropped for keyword terminals (#1618)
-
Fix Python comprehension filter grammar
Fix Python comprehension filter grammar
-
Tiny fix
Tiny fix
-
Merge pull request #1604 from nchammas/sphinx-errors
Merge pull request #1604 from nchammas/sphinx-errors Documentation tweaks to address Sphinx build errors and warnings
-
Merge pull request #1592 from lark-parser/scan_parse
Merge pull request #1592 from lark-parser/scan_parse Add Lark.scan() for finding grammar matches in text, and parsing them.
-
Fix lexer_callbacks silently dropped for keyword terminals
Fix lexer_callbacks silently dropped for keyword terminals 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 #1618.