Skip to content

[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

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 10, 2023

Also move 'repeat', 'each', and 'any' expression parsing to 'parseSequenceExpressionElement'.

rdar://107450487

@rintaro rintaro marked this pull request as ready for review July 10, 2023 22:47
@rintaro rintaro requested a review from ahoppen as a code owner July 10, 2023 22:47
@rintaro
Copy link
Member Author

rintaro commented Jul 10, 2023

swiftlang/swift#67206
@swift-ci Please test

Copy link
Member

@ahoppen ahoppen left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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) {
Copy link
Member

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:

Suggested change
if (self.peek().rawTokenKind != .identifier || self.peek().isAtStartOfLine) {
if self.peek().rawTokenKind != .identifier || self.peek().isAtStartOfLine {

Copy link
Member Author

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()
Copy link
Member

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.

Comment on lines +529 to +531
case (.repeat, let handle)?:
// 'repeat' is the start of a pack expansion expression.
return RawExprSyntax(parsePackExpansionExpr(repeatHandle: handle, flavor, pattern: pattern))
Copy link
Member

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()

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 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 {

Copy link
Member

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
@rintaro rintaro force-pushed the parse-each-self-rdar107450487 branch from 8de9e3a to f489551 Compare July 11, 2023 16:26
@rintaro
Copy link
Member Author

rintaro commented Jul 11, 2023

swiftlang/swift#67206
@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Jul 11, 2023

@swift-ci Please test Windows

@rintaro rintaro merged commit b0f8e70 into swiftlang:main Jul 11, 2023
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