-
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
error range includes leading trivia, instead of just the offending token #841
Comments
IIUC the problem stems from it being an unrecognized node at the top-most position: the trivia is not put anywhere. The real question is how to attach trivia to an unrecognized node. Otherwise, the solution is simply to advance the text index according to the trailing trivia, but that means the node text will contain all the trivia unparsed. Not sure we want that. Here's the output of a run with the solution mentioned above
|
Right now something like the following (noting
produces just one Instead, I propose to change the parser to produce a Proposed parsing output
I'm investigating this line. |
Ah, changing the way |
@OmarTawfik if you get the chance to read my comments above, I'll appreciate your input. |
Thanks for the investigation. We do attach leading trivia to individual tokens. For example, when parsing something like this, trivia would be attached to contract /* 1 */ foo { } I wonder if we can do the same here? modifying how trivia are stored, and adding the new nonterminal everywhere as you already guessed has many impacts, including increasing the tree size/depth, and changing how users process the results. So, instead of just creating a giant token (with both trivia and content) to attach the error to, I wonder if the parse result can include both tokens separately, with the error attached to the content only. |
But the problem is that the parser doesn't know what |
The specific combinator parsing the children of |
…ected nonterminal (#1172) Fixes #841 In examples like the following: ``` // some trivia unexpected ``` 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 specific `UNRECOGNIZED` kind, but after discussing with Omar, it was clear that the better option was to return the expected one: if we are parsing a `Statement`, then return a `Statement` with the trivia and the `UNRECOGNIZED` terminal at the end. This is realized in the `NoMatch` structure with a new field for the optional expected nonterminal kind, which is essentially attached in the `ParserResult::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 a `ParseResult::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.
Originally discovered in #840:
slang/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/with_var/generated/0.5.0-failure.yml
Lines 9 to 16 in e89c46c
The text was updated successfully, but these errors were encountered: