Skip to content

parsers: keep Choice alternatives in order - #27

Merged
rameel merged 2 commits into
mainfrom
fix-choice-order
Sep 22, 2026
Merged

rameel merged 2 commits into
mainfrom
fix-choice-order

Conversation

@rameel

@rameel rameel commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Choice merged every character class parser into a single Set and inserted it at the front of the alternatives.
The merged parser could then win before an earlier alternative and consume only one character.

var op = Choice(L("==").Void(), L('=').Void(), L('!').Void());
op.Parse("==").Length; // <-- actual: 1, expected: 2

L("==") is the first alternative and should match the whole input.

…sses

Merge only contiguous runs of character class parsers and keep each
merged parser in its place. Previously every character class was merged
into one parser and moved to the front, so a later character class could
win before an earlier alternative and consume only one character.
@rameel
rameel merged commit 0d9ae44 into main Sep 22, 2026
2 checks passed
@rameel
rameel deleted the fix-choice-order branch September 22, 2026 20:25
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.

1 participant