Skip to content

Commit 5ddbb84

Browse files
committed
[CoroutineAccessors] Added read.
1 parent d892c27 commit 5ddbb84

File tree

8 files changed

+46
-5
lines changed

8 files changed

+46
-5
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public let DECL_NODES: [Node] = [
113113
.keyword(.mutableAddressWithOwner),
114114
.keyword(.mutableAddressWithNativeOwner),
115115
.keyword(._read),
116+
.keyword(.read),
116117
.keyword(._modify),
117118
.keyword(.modify),
118119
.keyword(.`init`),

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public enum Keyword: CaseIterable {
246246
case `Protocol`
247247
case `protocol`
248248
case `public`
249+
case read
249250
case reasync
250251
case renamed
251252
case `repeat`
@@ -631,6 +632,8 @@ public enum Keyword: CaseIterable {
631632
return KeywordSpec("protocol", isLexerClassified: true)
632633
case .public:
633634
return KeywordSpec("public", isLexerClassified: true)
635+
case .read:
636+
return KeywordSpec("read", experimentalFeature: .coroutineAccessors)
634637
case .reasync:
635638
return KeywordSpec("reasync")
636639
case .renamed:

Sources/SwiftParser/TokenPrecedence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ enum TokenPrecedence: Comparable {
239239
.dependsOn, .scoped, .sending,
240240
// Accessors
241241
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
242-
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify, .modify,
242+
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify,
243243
// Misc
244244
.import:
245245
self = .declKeyword

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ extension AccessorDeclSyntax {
3232
case mutableAddressWithOwner
3333
case mutableAddressWithNativeOwner
3434
case _read
35+
#if compiler(>=5.8)
36+
@_spi(ExperimentalLanguageFeatures)
37+
#endif
38+
case read
3539
case _modify
3640
#if compiler(>=5.8)
3741
@_spi(ExperimentalLanguageFeatures)
@@ -63,6 +67,8 @@ extension AccessorDeclSyntax {
6367
self = .mutableAddressWithNativeOwner
6468
case TokenSpec(._read):
6569
self = ._read
70+
case TokenSpec(.read) where experimentalFeatures.contains(.coroutineAccessors):
71+
self = .read
6672
case TokenSpec(._modify):
6773
self = ._modify
6874
case TokenSpec(.modify) where experimentalFeatures.contains(.coroutineAccessors):
@@ -98,6 +104,8 @@ extension AccessorDeclSyntax {
98104
self = .mutableAddressWithNativeOwner
99105
case TokenSpec(._read):
100106
self = ._read
107+
case TokenSpec(.read):
108+
self = .read
101109
case TokenSpec(._modify):
102110
self = ._modify
103111
case TokenSpec(.modify):
@@ -133,6 +141,8 @@ extension AccessorDeclSyntax {
133141
return .keyword(.mutableAddressWithNativeOwner)
134142
case ._read:
135143
return .keyword(._read)
144+
case .read:
145+
return .keyword(.read)
136146
case ._modify:
137147
return .keyword(._modify)
138148
case .modify:
@@ -170,6 +180,8 @@ extension AccessorDeclSyntax {
170180
return .keyword(.mutableAddressWithNativeOwner)
171181
case ._read:
172182
return .keyword(._read)
183+
case .read:
184+
return .keyword(.read)
173185
case ._modify:
174186
return .keyword(._modify)
175187
case .modify:

Sources/SwiftSyntax/generated/Keyword.swift

+7
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ public enum Keyword: UInt8, Hashable, Sendable {
192192
case `Protocol`
193193
case `protocol`
194194
case `public`
195+
#if compiler(>=5.8)
196+
@_spi(ExperimentalLanguageFeatures)
197+
#endif
198+
case read
195199
case reasync
196200
case renamed
197201
case `repeat`
@@ -326,6 +330,8 @@ public enum Keyword: UInt8, Hashable, Sendable {
326330
self = .objc
327331
case "open":
328332
self = .open
333+
case "read":
334+
self = .read
329335
case "safe":
330336
self = .safe
331337
case "self":
@@ -980,6 +986,7 @@ public enum Keyword: UInt8, Hashable, Sendable {
980986
"Protocol",
981987
"protocol",
982988
"public",
989+
"read",
983990
"reasync",
984991
"renamed",
985992
"repeat",

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
242242
.keyword("mutableAddressWithOwner"),
243243
.keyword("mutableAddressWithNativeOwner"),
244244
.keyword("_read"),
245+
.keyword("read"),
245246
.keyword("_modify"),
246247
.keyword("modify"),
247248
.keyword("init")

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public struct AccessorBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNo
251251
///
252252
/// - `attributes`: ``AttributeListSyntax``
253253
/// - `modifier`: ``DeclModifierSyntax``?
254-
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `_modify` | `modify` | `init`)
254+
/// - `accessorSpecifier`: (`get` | `set` | `didSet` | `willSet` | `unsafeAddress` | `addressWithOwner` | `addressWithNativeOwner` | `unsafeMutableAddress` | `mutableAddressWithOwner` | `mutableAddressWithNativeOwner` | `_read` | `read` | `_modify` | `modify` | `init`)
255255
/// - `parameters`: ``AccessorParametersSyntax``?
256256
/// - `effectSpecifiers`: ``AccessorEffectSpecifiersSyntax``?
257257
/// - `body`: ``CodeBlockSyntax``?
@@ -418,6 +418,7 @@ public struct AccessorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclS
418418
/// - `mutableAddressWithOwner`
419419
/// - `mutableAddressWithNativeOwner`
420420
/// - `_read`
421+
/// - `read`
421422
/// - `_modify`
422423
/// - `modify`
423424
/// - `init`

Tests/SwiftParserTest/DeclarationTests.swift

+19-3
Original file line numberDiff line numberDiff line change
@@ -3338,8 +3338,8 @@ final class DeclarationTests: ParserTestCase {
33383338
func testCoroutineAccessors() {
33393339
assertParse(
33403340
"""
3341-
var i_rm: Int {
3342-
_read {
3341+
var irm: Int {
3342+
read {
33433343
yield _i
33443344
}
33453345
modify {
@@ -3366,6 +3366,22 @@ final class DeclarationTests: ParserTestCase {
33663366
)
33673367
]
33683368
)
3369-
3369+
assertParse(
3370+
"""
3371+
var ir_m: Int {
3372+
_modify {
3373+
yield &_i
3374+
}
3375+
1️⃣read {
3376+
yield _i
3377+
}
3378+
}
3379+
""",
3380+
diagnostics: [
3381+
DiagnosticSpec(
3382+
message: "unexpected code in variable"
3383+
)
3384+
]
3385+
)
33703386
}
33713387
}

0 commit comments

Comments
 (0)