Skip to content

[Recovery 3/7] Use higher level parsing primitives #744

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 22 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
@ahoppen ahoppen force-pushed the ahoppen/30-higher-level-primitives branch from e7e8b0d to 5682bce Compare September 8, 2022 16:47
@ahoppen ahoppen merged commit 5682bce into swiftlang:main Sep 8, 2022
@ahoppen ahoppen deleted the ahoppen/30-higher-level-primitives 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