Skip to content

Properly expect EOF after parser exits#117

Merged
msujew merged 1 commit into
mainfrom
msujew/expect-eof
Jun 24, 2026
Merged

Properly expect EOF after parser exits#117
msujew merged 1 commit into
mainfrom
msujew/expect-eof

Conversation

@msujew

@msujew msujew commented Jun 24, 2026

Copy link
Copy Markdown
Member

While we are perfectly capable of telling whether an input is too short (because parsing it fails), we're currently too lenient when an input is "too long" (i.e. the parser has already exited, but there are more tokens available).

This change addresses this by adding a dedicated ExpectEndOfInput method to the parser state, which generates an error on the first extra token it sees after the parser exits.

@msujew msujew requested a review from Lotes June 24, 2026 09:48
Comment thread parser/error_recovery.go
parserState.ReportMatch()
return la2, true
}
// Most other parser generators would attempt single-token insertion here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment? You are refering to nil tokens. I am not sure if this is still given, since you changed the if conditions.

@msujew msujew Jun 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecoverInline is called in ParserState.Consume. Consume still returns nil tokens, when they don't match the expected token - the comment is therefore still correct. Note that RecoverInline actually returns nil, not the EOF token.

@Lotes Lotes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks straight forward. Thanks.

@msujew msujew merged commit 4887a5f into main Jun 24, 2026
5 checks passed
@msujew msujew deleted the msujew/expect-eof branch June 24, 2026 10:17
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.

2 participants