-
Notifications
You must be signed in to change notification settings - Fork 20
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
Precise error location in UNRECOGNIZED by attaching trivia to the expected nonterminal #1172
Conversation
🦋 Changeset detectedLatest commit: 72d4858 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Likely this deserves a changeset, since it's changing the way an UNRECOGNIZED node is return when it's in the top-most position. |
crates/codegen/runtime/cargo/crate/src/runtime/parser/parser_support/parser_function.rs
Show resolved
Hide resolved
...snapshots/cst_output/ContractDefinition/unicode_in_doc_comments/generated/0.4.11-failure.yml
Show resolved
Hide resolved
...snapshots/cst_output/ContractDefinition/unicode_in_doc_comments/generated/0.4.11-failure.yml
Show resolved
Hide resolved
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.
Left a couple of questions.
Thanks!
crates/codegen/runtime/cargo/crate/src/runtime/parser/parser_support/parser_function.rs
Show resolved
Hide resolved
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, modulo the two unresolved comments (adding comments and a changeset).
Fixes #841
In examples like the following:
The parsing function was returning a terminal with
UNRECOGNIZED
kind and the entire text inside. Since a terminal cannot have trivia attached, we have to change the returning value to be a nonterminal. But which one? For a moment I thought of a new specificUNRECOGNIZED
kind, but after discussing with Omar, it was clear that the better option was to return the expected one: if we are parsing aStatement
, then return aStatement
with the trivia and theUNRECOGNIZED
terminal at the end. This is realized in theNoMatch
structure with a new field for the optional expected nonterminal kind, which is essentially attached in theParserResult::with_kind
method.The commit history contains a previous attempt in which the trivia was cached within the
NoMatch
struct. This added unnecessary complexity, so I decided against it.Note1: In a couple of places the code will use a
ParserResult::no_match(<default values>)
. Noting there was aParseResult::default()
function, I decided to use it instead, but I'm not sure if this is the expected use of the default function.Note2: I see that the error is one off at the end, probably accounting EOF? But was already the case before, so there's no real change there.