Skip to content

Commit

Permalink
Add support for '@retroactive' conformances in SwiftSyntaxParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Harlan Haskins committed Oct 9, 2023
1 parent 693a130 commit cbd5764
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public enum Keyword: CaseIterable {
case `repeat`
case required
case `rethrows`
case retroactive
case `return`
case reverse
case right
Expand Down Expand Up @@ -611,6 +612,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("required")
case .rethrows:
return KeywordSpec("rethrows", isLexerClassified: true)
case .retroactive:
return KeywordSpec("retroactive")
case .return:
return KeywordSpec("return", isLexerClassified: true)
case .reverse:
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ enum TokenPrecedence: Comparable {
.noDerivative,
.noescape,
.Sendable,
.retroactive,
.unchecked:
self = .exprKeyword

Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftParser/TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ enum TypeAttribute: TokenSpecSet {
case escaping
case noDerivative
case noescape
case retroactive
case Sendable
case unchecked

Expand All @@ -646,6 +647,7 @@ enum TypeAttribute: TokenSpecSet {
case TokenSpec(.noDerivative): self = .noDerivative
case TokenSpec(.noescape): self = .noescape
case TokenSpec(.Sendable): self = .Sendable
case TokenSpec(.retroactive): self = .retroactive
case TokenSpec(.unchecked): self = .unchecked
default: return nil
}
Expand All @@ -663,6 +665,7 @@ enum TypeAttribute: TokenSpecSet {
case .escaping: return .keyword(.escaping)
case .noDerivative: return .keyword(.noDerivative)
case .noescape: return .keyword(.noescape)
case .retroactive: return .keyword(.retroactive)
case .Sendable: return .keyword(.Sendable)
case .unchecked: return .keyword(.unchecked)
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ extension Parser {

mutating func parseTypeAttribute() -> RawAttributeListSyntax.Element {
switch peek(isAtAnyIn: TypeAttribute.self) {
case ._local, ._noMetadata, .async, .escaping, .noDerivative, .noescape, .Sendable, .unchecked, .autoclosure:
case ._local, ._noMetadata, .async, .escaping, .noDerivative, .noescape,
.retroactive, .Sendable, .unchecked, .autoclosure:
// Known type attribute that doesn't take any arguments
return parseAttributeWithoutArguments()
case .differentiable:
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public enum Keyword: UInt8, Hashable {
case `repeat`
case required
case `rethrows`
case retroactive
case `return`
case reverse
case right
Expand Down Expand Up @@ -620,6 +621,8 @@ public enum Keyword: UInt8, Hashable {
self = .nonisolated
case "nonmutating":
self = .nonmutating
case "retroactive":
self = .retroactive
case "unavailable":
self = .unavailable
default:
Expand Down Expand Up @@ -940,6 +943,7 @@ public enum Keyword: UInt8, Hashable {
"repeat",
"required",
"rethrows",
"retroactive",
"return",
"reverse",
"right",
Expand Down
8 changes: 8 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ final class DeclarationTests: ParserTestCase {
)
}

func testParseRetroactiveExtension() {
assertParse(
"""
extension Int: @retroactive Identifiable {}
"""
)
}

func testParseDynamicReplacement() {
assertParse(
"""
Expand Down

0 comments on commit cbd5764

Please sign in to comment.