Skip to content

Lexer: where a regex can start, /= begins a regex literal, not the compound assignment (#2525) - #2643

Merged
ehartford merged 1 commit into
fix-2554from
fix-2525
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-2554from
fix-2525

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: the / branch of Lexer.next_token (src/Lexer.w) returned
TK_SLASH_EQ for /= before it asked lexer_slash_starts_regex whether a
regex can start there, so /=> Some\((.*)\)/.replace(line, ...) lexed as
/= and failed with "expected expression". In a regex position /= has
no left operand to divide; the regex decision now comes first and /= is
the operator everywhere else (n /= 2 is unchanged).

Evidence:
before behav_2525_regex_starting_with_eq.w:11: error: expected expression
after Some(x) => x / true / 5 (stage1)

Test: test/behavior/behav_2525_regex_starting_with_eq.w

Closes #2525

…compound assignment (#2525)

Root cause: the `/` branch of Lexer.next_token (src/Lexer.w) returned
TK_SLASH_EQ for `/=` before it asked lexer_slash_starts_regex whether a
regex can start there, so `/=> Some\((.*)\)/.replace(line, ...)` lexed as
`/=` and failed with "expected expression". In a regex position `/=` has
no left operand to divide; the regex decision now comes first and `/=` is
the operator everywhere else (`n /= 2` is unchanged).

Evidence:
before  behav_2525_regex_starting_with_eq.w:11: error: expected expression
after   Some(x) => x / true / 5 (stage1)

Test: test/behavior/behav_2525_regex_starting_with_eq.w
@ehartford
ehartford added this pull request to stack #2645 October 25, 2026 19:58
@ehartford ehartford changed the title fix 2525 Lexer: where a regex can start, /= begins a regex literal, not the compound assignment (#2525) Oct 25, 2026
@ehartford
ehartford marked this pull request as ready for review October 25, 2026 20:07
@ehartford
ehartford merged commit 89ca9f6 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-2525 branch October 25, 2026 20:07
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.

one-liners: a regex literal starting with = lexes as the /= operator (/=> x/.replace(...) is "expected expression")

1 participant