-
-
Notifications
You must be signed in to change notification settings - Fork 21
Improve errors when keywords are used as identifiers #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
913a2e5 to
6d4855d
Compare
bal-e
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'm a bit surprised just how much stuff this relatively simple refactor involved.
| "true" => return ControlFlow::Break((Token::Bool(true), span)), | ||
| "false" => return ControlFlow::Break((Token::Bool(false), span)), | ||
| x => return ControlFlow::Break((Token::Ident(x), span)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
src/parser/token.rs
Outdated
| Token::Keyword(k) => { | ||
| return k.fmt(f); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe have fn Keyword::code(&self) -> &'static str and use that here? It might come in handy in a few other situations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably, although I don't like code. Maybe as_str?
Yeah well it's a couple things I suppose:
So all in all it's not trivial. |
Closes #153.
That example will now fail with this message:
The parser will also report more useful errors when a keyword is used when an identifier is expected, the difference is the note at the end of the error:
and the other case where this happens:
The superfluous
`mark has also been removed.