Skip to content

[Recovery 0a/7] Implement recovery in eat #688

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 1 commit into from
Sep 8, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Sep 1, 2022

This is quite a mechanical change without any changed functionality.


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.

@ahoppen ahoppen requested a review from CodaFi September 1, 2022 20:43
@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch 2 times, most recently from 1a4abbd to d284710 Compare September 6, 2022 13:25
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch from d284710 to 487db9f Compare September 6, 2022 19:42
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2022

@swift-ci Please test

}
}

func accepts(lexeme: Lexer.Lexeme, parser: Parser) -> Bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should live on an extension of the Lookahead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I assume you are worried because we do lookahead in accepts. So was I and I removed that feature in one of my follow-up commits in #718. I cherry-picked that commit to this PR now.

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch from 487db9f to aecec38 Compare September 7, 2022 05:31
@ahoppen
Copy link
Member Author

ahoppen commented Sep 7, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch from aecec38 to 0f49a05 Compare September 7, 2022 07:36
@ahoppen
Copy link
Member Author

ahoppen commented Sep 7, 2022

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch 2 times, most recently from 64eaa81 to 6ea881a Compare September 7, 2022 19:15
@ahoppen
Copy link
Member Author

ahoppen commented Sep 7, 2022

@swift-ci Please test

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.
if self.at(.inoutKeyword) {
let inoutKeyword = self.eat(.inoutKeyword)
elements.append(RawSyntax(inoutKeyword))
while let token = self.consume(ifAny: .inoutKeyword, .identifier, where: { (lexeme, parser) in
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems pretty messy.

Copy link
Member Author

@ahoppen ahoppen Sep 8, 2022

Choose a reason for hiding this comment

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

#744 will clean this up to

while let token = self.consume(ifAny: [.inoutKeyword], contextualKeywords: ["__shared", "__owned", "isolated", "_const"]), modifiersProgress.evaluate(currentToken) {

We just don’t have consume(ifAny:contextualKeywords:) at this stage yet.

let ident = self.consumeIdentifier()

var tokenList = [RawTokenSyntax]()
var loopProgress = LoopProgressCondition()
while self.at(.atSign) && loopProgress.evaluate(currentToken) {
tokenList.append(self.eat(.atSign))
while let atSign = self.consume(if: .atSign), loopProgress.evaluate(currentToken) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Extraneous whitespace

if self.at(.inoutKeyword) {
let inoutKeyword = self.eat(.inoutKeyword)
elements.append(RawSyntax(inoutKeyword))
while let token = self.consume(ifAny: .inoutKeyword, .identifier, where: { (lexeme, parser) in
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems pretty messy.

@CodaFi
Copy link
Contributor

CodaFi commented Sep 8, 2022

I think this has grown into at least two PRs: One that goes through and makes the simple eat -> expect transition, another that introduces the rest of the infrastructure here. It's hard for me to evaluate this much change in one place since it's no longer mechanical.

@ahoppen ahoppen force-pushed the ahoppen/recovery-for-eat branch from 6ea881a to 25d193d Compare September 8, 2022 15:31
@ahoppen
Copy link
Member Author

ahoppen commented Sep 8, 2022

I rebased this PR and made it only contain the first (mechanical) commit

@@ -79,7 +79,7 @@ extension TokenConsumer {
///
/// - Parameter kind: The kind of token to consume.
/// - Returns: A token of the given kind.
public mutating func eat(_ kind: RawTokenKind) -> Token {
public mutating func eatWithoutRecovery(_ kind: RawTokenKind) -> Token {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this utility into Parser and Lookup respectively if can no longer be shared. The new name doesn't read any better to me.

@@ -79,7 +79,7 @@ extension TokenConsumer {
///
/// - Parameter kind: The kind of token to consume.
/// - Returns: A token of the given kind.
public mutating func eat(_ kind: RawTokenKind) -> Token {
public mutating func eatWithoutRecovery(_ kind: RawTokenKind) -> Token {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this utility into Parser and Lookup respectively if can no longer be shared. The new name doesn't read any better to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is going to be removed by #741 again, so it shouldn’t make much difference where it lives.

@ahoppen ahoppen changed the title Implement recovery in eat [Recovery 0a/7] Implement recovery in eat Sep 8, 2022
@ahoppen ahoppen merged commit 25d193d into swiftlang:main Sep 8, 2022
@ahoppen ahoppen deleted the ahoppen/recovery-for-eat 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.

2 participants