Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public let DECL_NODES: [Node] = [
]
),

Node(
kind: .accessorYieldingModifier,
base: .syntax,
nameForDiagnostics: nil,
traits: [],
children: [ ??? ],
),

Node(
kind: .actorDecl,
base: .decl,
Expand Down
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public enum Keyword: CaseIterable {
case willSet
case wrt
case yield
case yielding

public var spec: KeywordSpec {
switch self {
Expand Down Expand Up @@ -692,6 +693,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("wrt")
case .yield:
return KeywordSpec("yield")
case .yielding:
return KeywordSpec("yielding")
}
}
}
20 changes: 20 additions & 0 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ extension Parser {
struct AccessorIntroducer {
var attributes: RawAttributeListSyntax
var modifier: RawDeclModifierSyntax?
var yielding: RawAccessorYieldingModifierSyntax?
var kind: AccessorDeclSyntax.AccessorSpecifierOptions
var unexpectedBeforeToken: RawUnexpectedNodesSyntax?
var token: RawTokenSyntax
Expand All @@ -1671,9 +1672,14 @@ extension Parser {
var look = self.lookahead()
let _ = look.consumeAttributeList()
let hasModifier = look.consume(ifAnyIn: AccessorModifier.self) != nil
let hasYielding = look.consume(if: TokenSpec(.yielding)) != nil
guard let (kind, _) = look.at(anyIn: AccessorDeclSyntax.AccessorSpecifierOptions.self) ?? forcedKind else {
return nil
}
guard !yielding || [AccessorDeclSyntax.AccessorSpecifierOptions.borrow, .mutate].contains(kind) else {
// `yielding` can only be followed by `borrow` or `mutate`
return nil
}

let attrs = self.parseAttributeList()

Expand All @@ -1692,10 +1698,24 @@ extension Parser {
modifier = nil
}

let yielding: RawAccessorYieldingModifierSyntax?
if hasYielding {
let (unexpectedBeforeYieldingName, yieldingName) = self.expect(TokenSpec(.yielding))
yielding = RawAccessorYieldingModifierSyntax(
unexpectedBeforeYieldingName,
name: yieldingName,
arena: self.arena
)
} else {
yielding = nil
}

let (unexpectedBeforeIntroducer, introducer) = self.expect(kind.spec)

return AccessorIntroducer(
attributes: attrs,
modifier: modifier,
yielding: yielding,
kind: kind,
unexpectedBeforeToken: unexpectedBeforeIntroducer,
token: introducer
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ enum TokenPrecedence: Comparable {
.dependsOn, .scoped, .sending,
// Accessors
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify, .mutate,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify, .mutate, .yielding,
// Misc
.import, .using:
self = .declKeyword
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3467,12 +3467,18 @@ final class DeclarationTests: ParserTestCase {
read {
yield _i
}
yielding borrow {
yield _i
}
_modify {
yield &_i
}
modify {
yield &_i
}
yielding mutate {
yield &_i
}
}
""",
experimentalFeatures: .coroutineAccessors
Expand Down
Loading