Skip to content

Simplify checking if a token can be an argument label #1911

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 2 commits into from
Jul 23, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 17, 2023

Mostly, change self.currentToken.canBeArgumentLabel to self.atArgumentLabel.

Also some other miscellaneous smaller improvements in the parser.

@ahoppen ahoppen requested a review from bnbarham July 17, 2023 14:05
case .identifier, .wildcard:
// Identifiers, escaped identifiers, and '_' can be argument labels.
return true
case .dollarIdentifier:
return allowDollarIdentifier
case .keyword(.inout):
// `inout` is reserved as an argument label for historical reasons.
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this is copied from above, but wouldn't this make it not reserved, ie. inout cannot be an argument label?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Updated

@@ -235,19 +235,50 @@ extension Parser {
mutating func parseSimpleType(
stopAtFirstPeriod: Bool = false
) -> RawTypeSyntax {
enum TypeBaseStart: TokenSpecSet {
Copy link
Contributor

Choose a reason for hiding this comment

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

So much boilerplate :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a stupid question: is it possible to use one of the generated ones?

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 don’t think there’s any one that has these cases because we do walk into different parsing functions based on the token, similar to ExpressionModifierKeyword.

@ahoppen ahoppen force-pushed the ahoppen/isargumentlabel branch from 4b4ae9c to 0664c79 Compare July 18, 2023 15:47
@ahoppen
Copy link
Member Author

ahoppen commented Jul 18, 2023

@swift-ci Please test

case .wildcard: return .wildcard
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: newline 😬

@@ -235,19 +235,50 @@ extension Parser {
mutating func parseSimpleType(
stopAtFirstPeriod: Bool = false
) -> RawTypeSyntax {
enum TypeBaseStart: TokenSpecSet {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a stupid question: is it possible to use one of the generated ones?

@ahoppen ahoppen force-pushed the ahoppen/isargumentlabel branch from 0664c79 to 00845be Compare July 18, 2023 20:55
@ahoppen ahoppen force-pushed the ahoppen/isargumentlabel branch from 00845be to 011f790 Compare July 23, 2023 15:40
@ahoppen
Copy link
Member Author

ahoppen commented Jul 23, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 23, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 70cdb8e into swiftlang:main Jul 23, 2023
@ahoppen ahoppen deleted the ahoppen/isargumentlabel branch July 23, 2023 17:45
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.

3 participants