fix: include token type in unexpected token error messages - #463
Open
Pastalikek65 wants to merge 2 commits into
Open
fix: include token type in unexpected token error messages#463Pastalikek65 wants to merge 2 commits into
Pastalikek65 wants to merge 2 commits into
Conversation
Unexpected token errors now include the symbolic name of the lexer token type when one exists, e.g. "unexpected token \"group\" of type Keyword". Token types without a symbolic name (such as literals) are unchanged. Fixes alecthomas#265.
This was referenced Aug 9, 2026
alecthomas
approved these changes
Aug 9, 2026
alecthomas
requested changes
Aug 9, 2026
alecthomas
left a comment
Owner
There was a problem hiding this comment.
Mmm. I think this should use the same <lower-symbol> syntax that we already use elsewhere for grammars.
Author
|
Thanks @alecthomas! I've updated the format to use the same |
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.
Unexpected token errors now report the symbolic name of the lexer's token type when one exists, e.g.:
Token types without a symbolic name (such as literals) keep the previous format, e.g.:
This is the format suggested by @alecthomas in #265 ("unexpected token "group" of type keyword").
Implementation notes:
parseContextnow carries the lexer's symbol table (built once from the parser'slexer.Definition); everyUnexpectedTokenErrorconstruction point (7 sites acrossparser.go/nodes.go) fills the newTokenTypefield.UnexpectedTokenError.TokenTypeis ordered after the pre-existing exported fields, so external positional struct literals remain source-compatible.Verification:
go test ./...(root +_examples), golangci-lint run — no new issues vs. baseline.Fixes #265.