Skip to content

Commit 7c1c56c

Browse files
authored
Merge pull request #2361 from DougGregor/parseable-codeblocksyntax
2 parents 4af9b16 + 576cbb6 commit 7c1c56c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public let COMMON_NODES: [Node] = [
5656
kind: .codeBlock,
5757
base: .syntax,
5858
nameForDiagnostics: "code block",
59+
parserFunction: "parseCodeBlock",
5960
traits: [
6061
"Braced",
6162
"WithStatements",

Sources/SwiftParser/generated/LayoutNodes+Parsable.swift

+18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ extension CodeBlockItemSyntax: SyntaxParseable {
126126
}
127127
}
128128

129+
extension CodeBlockSyntax: SyntaxParseable {
130+
public static func parse(from parser: inout Parser) -> Self {
131+
// Keep the parser alive so that the arena in which `raw` is allocated
132+
// doesn’t get deallocated before we have a chance to create a syntax node
133+
// from it. We can’t use `parser.arena` as the parameter to
134+
// `Syntax(raw:arena:)` because the node might have been re-used during an
135+
// incremental parse and would then live in a different arena than
136+
// `parser.arena`.
137+
defer {
138+
withExtendedLifetime(parser) {
139+
}
140+
}
141+
let node = parser.parseCodeBlock()
142+
let raw = RawSyntax(parser.parseRemainder(into: node))
143+
return Syntax(raw: raw, rawNodeArena: raw.arena).cast(Self.self)
144+
}
145+
}
146+
129147
extension DeclSyntax: SyntaxParseable {
130148
public static func parse(from parser: inout Parser) -> Self {
131149
// Keep the parser alive so that the arena in which `raw` is allocated

Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extension ClosureParameterSyntax: SyntaxExpressibleByStringInterpolation {}
2626

2727
extension CodeBlockItemSyntax: SyntaxExpressibleByStringInterpolation {}
2828

29+
extension CodeBlockSyntax: SyntaxExpressibleByStringInterpolation {}
30+
2931
extension DeclSyntax: SyntaxExpressibleByStringInterpolation {}
3032

3133
extension EnumCaseParameterSyntax: SyntaxExpressibleByStringInterpolation {}

0 commit comments

Comments
 (0)