-
Notifications
You must be signed in to change notification settings - Fork 441
[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
Conversation
@swift-ci Please test |
1a4abbd
to
d284710
Compare
@swift-ci Please test |
d284710
to
487db9f
Compare
@swift-ci Please test |
Sources/SwiftParser/Modifiers.swift
Outdated
} | ||
} | ||
|
||
func accepts(lexeme: Lexer.Lexeme, parser: Parser) -> Bool { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
487db9f
to
aecec38
Compare
@swift-ci Please test |
aecec38
to
0f49a05
Compare
@swift-ci Please test |
64eaa81
to
6ea881a
Compare
@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.
Sources/SwiftParser/Types.swift
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty messy.
There was a problem hiding this comment.
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.
Sources/SwiftParser/Statements.swift
Outdated
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Extraneous whitespace
Sources/SwiftParser/Types.swift
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty messy.
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. |
6ea881a
to
25d193d
Compare
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
eat
eat
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.