Skip to content

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Nov 15, 2022

Few fixes to member parsing:

  • Parse .Type and .Protocol as MetatypeTypeSyntax
  • Parse keywords as identifiers
  • Generate a missing identifier rather than unexpected nodes if the next
    token is on a new line
  • Diagnose extraneous whitespace after . if there was no leading
    whitespace
  • Remove .prefixPeriod since it is no longer used

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

Note that this depends on #1076 (which is included in this PR right now) and the FIXME in https://github.com/apple/swift/pull/62092should be able to be removed after this (looks like there's already a MetatypeTypeSyntax visit).

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham bnbarham force-pushed the fix-metatypes branch 2 times, most recently from 853619a to 75cabed Compare December 1, 2022 02:25
@bnbarham
Copy link
Contributor Author

bnbarham commented Dec 1, 2022

@swift-ci please test

@bnbarham bnbarham force-pushed the fix-metatypes branch 2 times, most recently from c74a505 to 6c5b7aa Compare December 3, 2022 21:28
@bnbarham
Copy link
Contributor Author

bnbarham commented Dec 3, 2022

@swift-ci please test

@bnbarham bnbarham changed the title Parse .Type and .Protocol as MetatypeTypeSyntax Fix member type/expression parsing Dec 3, 2022
@bnbarham
Copy link
Contributor Author

bnbarham commented Dec 3, 2022

So I went down a rabbit hole here 😅 ... if you could have another look that'd be great @rintaro / @ahoppen 🙇

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

swiftlang/swift#62561

@swift-ci please test

@bnbarham bnbarham force-pushed the fix-metatypes branch 3 times, most recently from 7b425a9 to dfe5ff7 Compare December 15, 2022 01:27
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

bnbarham added a commit to bnbarham/swift-format that referenced this pull request Dec 20, 2022
@bnbarham
Copy link
Contributor Author

swiftlang/swift-format#463

@swift-ci please test

  - Parse `.Type` and `.Protocol` as `MetatypeTypeSyntax`
  - Parse keywords in member position as identifiers
  - Generate a missing identifier rather than unexpected nodes if the next
    token is on a new line
  - Diagnose extraneous whitespace after `.` if there was no leading
    whitespace
  - Remove `.prefixPeriod` since it is no longer used
@bnbarham
Copy link
Contributor Author

swiftlang/swift-format#463

@swift-ci please test

@bnbarham bnbarham merged commit a2d31e8 into swiftlang:main Dec 21, 2022
@bnbarham bnbarham deleted the fix-metatypes branch December 21, 2022 19:29
Comment on lines -847 to -878
mutating func canParseOldStyleProtocolComposition() -> Bool {
self.eat(.protocolKeyword)

// Check for the starting '<'.
guard self.currentToken.starts(with: "<") else {
return false
}

self.consumePrefix("<", as: .leftAngle)

// Check for empty protocol composition.
if self.currentToken.starts(with: ">") {
self.consumePrefix(">", as: .rightAngle)
return true
}

// Parse the type-composition-list.
var loopProgress = LoopProgressCondition()
repeat {
guard self.canParseTypeIdentifier() else {
return false;
}
} while self.consume(if: .comma) != nil && loopProgress.evaluate(currentToken)

// Check for the terminating '>'.
guard self.currentToken.starts(with: ">") else {
return false
}
self.consumePrefix(">", as: .rightAngle)

return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@bnbarham Was this removed on purpose?

Copy link
Member

@rintaro rintaro Dec 27, 2022

Choose a reason for hiding this comment

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

@AnthonyLatsis Yes, in SwiftParser we decided not to support old style protocol composition at all (there's no parseOldStyleProtocolComposition().) So keeping canParseOldStyleProtocolComposition() doesn't make sense.

ahoppen pushed a commit to ahoppen/swift-format that referenced this pull request Jan 27, 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.

4 participants