Skip to content

[Recovery 5/7] Rewrite isStartOfDeclaration to more closely match the parser implementation #746

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 31 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.
@ahoppen ahoppen force-pushed the ahoppen/50-rewrite-at-start-of branch from 1f3f071 to f6943b6 Compare September 8, 2022 16:47
@ahoppen ahoppen merged commit f6943b6 into swiftlang:main Sep 8, 2022
@ahoppen ahoppen deleted the ahoppen/50-rewrite-at-start-of branch January 14, 2023 08:21
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.

1 participant