Skip to content

Conversation

@ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 23, 2023

The main problem here was that we were accepting self and Self in expectIdentifier but not handling that in the syntax tree. I went through every call of expectIdentifier and checked what the C++ parser does to maintain the behavior. Where we need to accept self or Self for compatibility reasons, it is now remapped to an identifier.

In other cases, the syntax node definitions just needed to be updated.

These problems were found by the verification added in #1339.

@ahoppen ahoppen requested review from bnbarham and rintaro March 23, 2023 23:12
@ahoppen ahoppen force-pushed the ahoppen/token-kind-mismatches branch 2 times, most recently from 7596ccb to f028ced Compare March 23, 2023 23:15
@ahoppen
Copy link
Member Author

ahoppen commented Mar 24, 2023

@swift-ci Please test

let (name, _) = self.parseDeclNameRef(flags)
mutating func parseTypeNameWithGenerics(allowKeywordAsName: Bool) -> (RawTokenSyntax, RawGenericArgumentClauseSyntax?) {
let name: RawTokenSyntax
if let identOrSelf = self.consume(if: .identifier, .keyword(.Self), .keyword(.Self)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Self twice

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, one of them should’ve been lowercase self.

Child(
name: "Identifier",
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .keyword(text: "self"), .keyword(text: "Self"), .keyword(text: "init")])
Copy link
Contributor

Choose a reason for hiding this comment

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

Editor placeholder is always <##> so ... seems weird we'd need this.

Copy link
Member Author

Choose a reason for hiding this comment

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

You’re right, we don’t actually need it here.

@ahoppen ahoppen force-pushed the ahoppen/token-kind-mismatches branch from f028ced to fa14be6 Compare March 24, 2023 20:15
@ahoppen
Copy link
Member Author

ahoppen commented Mar 24, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 27, 2023

@swift-ci Please test Windows

…match the token kinds in the syntax node definitions

The main problem here was that we were accepting `self` and `Self` in `expectIdentifier` but not handling that in the syntax tree. I went through every call of `expectIdentifier` and checked what the C++ parser does to maintain the behavior. Where we need to accept `self` or `Self` for compatibility reasons, it is now remapped to an identifier.
@ahoppen ahoppen force-pushed the ahoppen/token-kind-mismatches branch from fa14be6 to aea4442 Compare March 28, 2023 17:58
@ahoppen
Copy link
Member Author

ahoppen commented Mar 28, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 28, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 9df5d69 into swiftlang:main Mar 29, 2023
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Mar 31, 2023
…matches

Fix multiple cases where the parser produced token kinds that didn’t match the token kinds in the syntax node definitions
@ahoppen ahoppen deleted the ahoppen/token-kind-mismatches branch April 18, 2023 18:07
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