-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Precise error location in UNRECOGNIZED by attaching trivia to the exp…
…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.
- Loading branch information
1 parent
9f3c44a
commit 6102886
Showing
33 changed files
with
292 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
Improved error recovery, where leading trivia are always parsed and included before an erroneous terminal. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.