Skip to content

Commit ba286af

Browse files
committed
[Variadic Generics] Add parsing support for a contextual 'each' keyword applied
to type parameter pack references.
1 parent 56f99d0 commit ba286af

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/SwiftParser/Patterns.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ extension Parser.Lookahead {
350350
// If the first name wasn't "isolated", we're done.
351351
if !self.atContextualKeyword("isolated") &&
352352
!self.atContextualKeyword("some") &&
353-
!self.atContextualKeyword("any") {
353+
!self.atContextualKeyword("any") &&
354+
!self.atContextualKeyword("each") {
354355
return true
355356
}
356357

Sources/SwiftParser/Types.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ extension Parser {
120120
/// protocol-composition-continuation → type-identifier | protocol-composition-type
121121
@_spi(RawSyntax)
122122
public mutating func parseSimpleOrCompositionType() -> RawTypeSyntax {
123+
// 'each' is a contextual keyword for a pack reference.
124+
if let each = consume(ifAny: [], contextualKeywords: ["each"]) {
125+
let packType = parseSimpleType()
126+
return RawTypeSyntax(RawPackReferenceTypeSyntax(
127+
eachKeyword: each, packType: packType, arena: self.arena))
128+
}
129+
123130
let someOrAny = self.consume(ifAny: [], contextualKeywords: ["some", "any"])
124131

125132
var base = self.parseSimpleType()

0 commit comments

Comments
 (0)