Skip to content

[Recovery 7/7] Improve recovery in #if blocks #748

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

Merged
merged 37 commits into from
Sep 8, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Sep 8, 2022

At the moment this doesn’t change anything because all places that call `eat` have previous checks that make sure the parser is currently positioned at the expected token.

In the future, this will allow us to start parsing functions that `eat` a token at a different token and this function is responsible for eating all intermediate tokens until the expected one.
Use one of the following alternatives instead:
- `expect` (mostly at start of productions)
- `consume(if:)` where this paradigm is applicable
- `consume(if:followedBy:)` to consume two tokens at once
- A new `at(anyIn:)` paradigm that allows the parser to check if it is currently positioned at a known token kind, which can be exhausitively switched. If this is the case, the token can be safely consumed using a handle.
  - This function might seem overly complicated at the moment but it should allow us to later switch to a similar function that also does recovery.
This makes it easier to call it from other functions and forward the expected token kinds.
# Conflicts:
#	Sources/SwiftParser/Lookahead.swift
#	Sources/SwiftParser/TokenConsumer.swift
We aren’t using this anywhere, but it seems like useful functionality in general.
…entation

This allows us to share a few token kinds betewen `isStartOfDeclaration` and the actual parser.
If the item is not an expression, we can try skipping more tokens to parse a declaration.
This is no longer satisfied if the token text is synthesized from a StaticString.
If the current token is not the start of a declaration, check if we can consume unexpected tokens to reach the declaration’s introducer.
This makes it easier to implement recovery in the future.
@ahoppen ahoppen force-pushed the ahoppen/70-pound-if-recovery branch from 6ed5431 to 198d526 Compare September 8, 2022 16:47
@ahoppen
Copy link
Member Author

ahoppen commented Sep 8, 2022

@swift-ci Please test

@ahoppen ahoppen marked this pull request as ready for review September 8, 2022 18:03
@ahoppen ahoppen requested a review from CodaFi September 8, 2022 18:03
@ahoppen ahoppen merged commit 1ecfa30 into swiftlang:main Sep 8, 2022
@ahoppen ahoppen deleted the ahoppen/70-pound-if-recovery branch September 8, 2022 19:42
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.

2 participants