Skip to content

fix: Don't ignore IncompleteMatch in OneOrMoreHelper#593

Closed
Xanewok wants to merge 3 commits intoNomicFoundation:mainfrom
Xanewok:repetition-dont-match-optional-incomplete
Closed

fix: Don't ignore IncompleteMatch in OneOrMoreHelper#593
Xanewok wants to merge 3 commits intoNomicFoundation:mainfrom
Xanewok:repetition-dont-match-optional-incomplete

Conversation

@Xanewok
Copy link
Copy Markdown
Contributor

@Xanewok Xanewok commented Sep 8, 2023

Parsing some input in when the first element is optional shouldn't be accepted as empty.

Parsing *some* input in when the first element is optional shouldn't be
accepted as empty.
@Xanewok Xanewok requested a review from a team as a code owner September 8, 2023 19:53
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Sep 8, 2023

⚠️ No Changeset found

Latest commit: f23047b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@AntonyBlakey AntonyBlakey added this pull request to the merge queue Sep 15, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 15, 2023
@AntonyBlakey AntonyBlakey added this pull request to the merge queue Sep 15, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 15, 2023
Xanewok and others added 2 commits September 15, 2023 11:38
- NumericExpression (Rule): # 0..1 "2"
- DecimalLiteral (Token): "2" # 0..1
- SKIPPED (Token): " * new\n" # 1..8
- BinaryExpression (Rule): # 1..3 " *"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why BinaryExpression is produced with one child (the binary operator) without any operands. Is this expected?

│ ╰──── Error occurred here.
───╯
- >
Error: Expected OpenBrace or OpenParen.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why are we expecting OpenBrace or OpenParen here. Since function call expressions are postfix operators, shouldn't we be skipping it alltogether? am I missing something?

Copy link
Copy Markdown
Contributor

@OmarTawfik OmarTawfik left a 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

@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Sep 20, 2023

I investigated #593 (comment) and it seems that the removed branch is specifically used in the precedence parser: if the input is complete, the nodes are reduced, however if the sequence is incomplete, it is not, hence why we see the flat [2, *, incomplete_new] node sequence.

I believe that the change itself is correct (partially parsing first term in ZeroOrMore should return an partial parse, not a valid "empty" one) but this doesn't surface in our regular parsing code, as the only place it's used is in the SeparatedBy, which is transformed as (Parser (Separator Parser *)) - the only separators we have are tokens, so it's impossible to have a partial parse on those.

We should probably separate this branch to the precedence parser code itself or adapt the ZeroOrMore code to distinguish between the regular and precedence parsing. @AntonyBlakey thoughts?

Separately from that, we still need to improve error recovery during precedence parsing. Maybe changing the notion of IncompleteMatch to Match([nodes, SKIPPED("")]) would be enough to leverage existing recovery infra, I can investigate that in a follow-up.

@AntonyBlakey AntonyBlakey added this pull request to the merge queue Sep 21, 2023
@AntonyBlakey AntonyBlakey removed this pull request from the merge queue due to a manual request Sep 21, 2023
@Xanewok Xanewok marked this pull request as draft September 21, 2023 14:13
@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Sep 21, 2023

Changing to draft as we might need to address the interaction with precedence parsing before landing this.

github-merge-queue bot pushed a commit that referenced this pull request Sep 26, 2023
Based on #593.

Implements a dedicated `SeparatedHelper` (no state, can change to a free
function) that implements recovering from partial matches in separated
lists.

There are 3 ways we can recover:
1. a separatee matches but unexpected tokens follow before a separator
2. a separatee is partially matched
3. a separatee can't be parsed

Ideally we should recover in all three cases, however because the the
trailing separator is not mandatory (nor legal), cases 1. and 3. are
tricky. In case 2 The separated-by lists are not always in a delimited
group (e.g. `IdentifierPath`) and so there's no sure way to bound the
recovery, as the unexpected tokens (i.e. not a separator) can be already
part of the outer parse.

For instance, `0.0.0 || 0.0.0` (case 1) or `0.0. || 0.0.0` (case 3)
might attempt to recover by skipping the ` || 0` part. Until we
constrain the error recovery with a la FOLLOW for the recovering parser,
we can't reliably recover errors for now in these cases.
@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Oct 31, 2023

I'll close this to not pollute the PRs; I'll come back to this once we revisit ER at some point.

@Xanewok Xanewok closed this Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants