-
Notifications
You must be signed in to change notification settings - Fork 693
Improve error message for identifiers with leading underscore #28897
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
Improve error message for identifiers with leading underscore #28897
Conversation
|
Argh, I didn't see it before (and I should've checked first), but now after pasting |
|
In https://github.com/ProvableHQ/leo/blob/mainnet/compiler/parser-lossless/src/lib.rs, we already have a function that checks identifiers. Is it better to do this check there? I'm not sure how I feel about inserting invalid regrexes in the tokenizer 🤔 Also, when adding new errors, we have this quirk that new errors should always be appended at the end of the errors file, so that old error codes don't change. |
|
Point 1 - hmm, you're talking about Point 2 - ahhh, good point, thanks. I can adjust it. Let me know about point 1 and my first comment in the PR, maybe we don't need it anymore. Not sure. |
Oh I now undersatnd. Yeah then doing it in in the tokenizer is probably the way to go. Thanks! |
| @formatted | ||
| identifier_cannot_start_with_underscore { | ||
| args: (), | ||
| msg: "Identifier cannot start with an underscore", |
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.
| msg: "Identifier cannot start with an underscore", | |
| msg: "Identifiers cannot start with an underscore.", |
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.
Done.
When users write identifiers starting with underscore,
(e.g.: let _c: u32), the parser produces an uninformative error.
Root cause of that is that lexer splits `_c` into two separate tokens,
and the parser had no grammar rule matching the pattern, so LARLPOP
generates a generir error listing what tokens it expected at that
position (which happened to be '(' for tuple destructuring).
So, this adds new lexer token - `InvalidLeadingUnderscoreIdent` that
catches any leading underscore next to identifiers.
88a72cb to
019ccf1
Compare
|
Also moved the error at the end of the file as discussed, removed a lot of changes with newly updated error codes. |
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.
LGTM!
|
Closing in favour of #28909 |
When users write identifiers starting with underscore, (e.g.: let _c: u32), the parser produces an uninformative error.
Root cause of that is that lexer splits
_cinto two separate tokens, and the parser had no grammar rule matching the pattern, so LARLPOP generates a generir error listing what tokens it expected at that position (which happened to be '(' for tuple destructuring).So, this adds new lexer token -
InvalidLeadingUnderscoreIdentthat catches any leading underscore next to identifiers.Before:
After:
Resolves: #28755