Skip to content

parsers: make Return produce an empty matched segment - #40

Merged
rameel merged 1 commit into
mainfrom
return-matched-segment
Oct 9, 2026
Merged

rameel merged 1 commit into
mainfrom
return-matched-segment

Conversation

@rameel

@rameel rameel commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Return consumes no input, but it left the matched segment of the previous parser in the context. Text() and Map then read that stale text: L("abc").Then(Return(42).Text()) produced "abc" instead of "".

Return now calls Advance(0), as Eof, Optional and DefaultOnFail already do. The segment is empty and sits at the position where Return was applied.

Return consumes no input, but it left the matched segment of the
previous parser in the context. Text() and Map then read that stale
text: L("abc").Then(Return(42).Text()) produced "abc" instead of "".

Return now calls Advance(0), as Eof, Optional and DefaultOnFail already
do. The segment is empty and sits at the position where Return was
applied.
@rameel
rameel merged commit c44f266 into main Oct 9, 2026
2 checks passed
@rameel
rameel deleted the return-matched-segment branch October 9, 2026 14:24
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