fix: tokenize expressions correctly in function/macro args#431
Open
toddr-bot wants to merge 1 commit into
Open
fix: tokenize expressions correctly in function/macro args#431toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
The tokenizer had two bugs that caused expressions like `show(x-2)` and `show(x/2)` to be misparsed when written without spaces: 1. The number regex `-?\d+` consumed the minus sign as part of a negative number literal, so `x-2` tokenized as IDENT:'x' NUMBER:'-2' instead of IDENT:'x' BINOP:'-' NUMBER:'2'. Fix: when a negative number follows a value-producing token (IDENT, NUMBER, LITERAL, ')' or ']'), split it into a BINOP '-' and a positive NUMBER. 2. The filename regex `\/\w+` matched `/2` as a filename, so `x/2` tokenized as FILENAME:'x/2'. Fix: require filename path segments to start with a letter or underscore, not a digit. Standalone negative literals like `-3` and `[-1, -2]` continue to work. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Recreated from #345 (auto-closed when the |
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.
What
Fix tokenizer so that expressions like
show(x-2)andshow(x/2)work correctly without spaces around operators.Why
Fixes GH #315. The tokenizer misparses expressions inside function/macro arguments when there are no spaces around
-and/operators:show(x-2)silently passesx(value 5) instead ofx-2(value 3) — the-2is consumed as a separate negative number argumentshow(x/2)throws a parse error —/2is consumed as a filename tokenWith spaces (
show(x - 2),show(x / 2)) everything works fine. The bug is purely in the tokenizer's regex.How
Two targeted changes in
tokenise_directive():Negative number splitting: When a negative number token immediately follows a value-producing token (IDENT, NUMBER, LITERAL,
),]), split it intoBINOP '-'+ positiveNUMBER. This preserves standalone negative literals like-3and[-1, -2].Filename regex tightening: Changed
\/\w+to\/[a-zA-Z_]\w*so that/2is not matched as a filename. Path segments after/or::now require a leading letter or underscore, which matches real template filenames.Testing
t/macro.tcovering expressions in macro args, negative literals, and multi-arg expressions🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 37 insertions(+), 1 deletion(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline