-
Notifications
You must be signed in to change notification settings - Fork 439
[Parser] Accept 'self' after 'each' #1895
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
swiftlang/swift#67206 |
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 is much nicer. Thanks. Three minor nitpicks.
|
||
case (.each, let handle)?: | ||
// `each` is only contextually a keyword, if it's followed by an | ||
// identifier or keyword on the same line. We do this to ensure that we do |
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.
// identifier or keyword on the same line. We do this to ensure that we do | |
// identifier or 'self' on the same line. We do this to ensure that we do |
case (.each, let handle)?: | ||
// `each` is only contextually a keyword, if it's followed by an | ||
// identifier or keyword on the same line. We do this to ensure that we do | ||
// not break any copy functions defined by users. This is following with |
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.
// not break any copy functions defined by users. This is following with | |
// not break any 'each' functions defined by users. This is following with |
case (.any, _)?: | ||
// `any` is only contextually a keyword if it's followed by an identifier | ||
// on the same line. | ||
if (self.peek().rawTokenKind != .identifier || self.peek().isAtStartOfLine) { |
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 would write this in terms of TokenSpec
:
if (self.peek().rawTokenKind != .identifier || self.peek().isAtStartOfLine) { | |
if self.peek().rawTokenKind != .identifier || self.peek().isAtStartOfLine { |
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.
Changed to
guard case TokenSpec(.identifier, allowAtStartOfLine: false) = self.peek() else {
break EXPR_PREFIX
}
break EXPR_PREFIX | ||
} | ||
// 'any' is parsed as a part of 'ty'. | ||
let ty = self.parseType() |
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.
Nitpick. Let’s name the variable type
. No reason to save the two characters here.
case (.repeat, let handle)?: | ||
// 'repeat' is the start of a pack expansion expression. | ||
return RawExprSyntax(parsePackExpansionExpr(repeatHandle: handle, flavor, pattern: pattern)) |
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 just noticed that we already never parse repeat
as a function call in the following (not a regression introduced by this PR, this just made me realize it…
func repeat() {}
repeat()
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.
You need backticks. Before repeat
expression for SE-0393 repeat
was only for repeat {} while <condition>
statement. Now repeat
is a statement only if it's followed by {
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.
Ah, thanks for reminding me. Now that you mention it, I think I left the same comment somewhere else already 🤦🏽
Also move 'repeat', 'each', and 'any' expression parsing to 'parseSequenceExpressionElement'. rdar://107450487
8de9e3a
to
f489551
Compare
swiftlang/swift#67206 |
@swift-ci Please test Windows |
Also move 'repeat', 'each', and 'any' expression parsing to 'parseSequenceExpressionElement'.
rdar://107450487