From 331292ff4c9d4ae54fe5710941c639ad7f5a904d Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Wed, 15 Nov 2023 15:57:53 -0800 Subject: [PATCH 1/2] Make CodeBlockSynax parseable --- CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift b/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift index 9ba842e6bef..b6109579836 100644 --- a/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift +++ b/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift @@ -56,6 +56,7 @@ public let COMMON_NODES: [Node] = [ kind: .codeBlock, base: .syntax, nameForDiagnostics: "code block", + parserFunction: "parseCodeBlock", traits: [ "Braced", "WithStatements", From 576cbb6aea8e289d34aef156cd50484165c23c6a Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Wed, 15 Nov 2023 15:59:40 -0800 Subject: [PATCH 2/2] Regenerate --- .../generated/LayoutNodes+Parsable.swift | 18 ++++++++++++++++++ ...ibleByStringInterpolationConformances.swift | 2 ++ 2 files changed, 20 insertions(+) diff --git a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift index 796dcc276f2..477650b20b2 100644 --- a/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift +++ b/Sources/SwiftParser/generated/LayoutNodes+Parsable.swift @@ -126,6 +126,24 @@ extension CodeBlockItemSyntax: SyntaxParseable { } } +extension CodeBlockSyntax: SyntaxParseable { + public static func parse(from parser: inout Parser) -> Self { + // Keep the parser alive so that the arena in which `raw` is allocated + // doesn’t get deallocated before we have a chance to create a syntax node + // from it. We can’t use `parser.arena` as the parameter to + // `Syntax(raw:arena:)` because the node might have been re-used during an + // incremental parse and would then live in a different arena than + // `parser.arena`. + defer { + withExtendedLifetime(parser) { + } + } + let node = parser.parseCodeBlock() + let raw = RawSyntax(parser.parseRemainder(into: node)) + return Syntax(raw: raw, rawNodeArena: raw.arena).cast(Self.self) + } +} + extension DeclSyntax: SyntaxParseable { public static func parse(from parser: inout Parser) -> Self { // Keep the parser alive so that the arena in which `raw` is allocated diff --git a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift index 32c185bf318..455f1edbde7 100644 --- a/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift +++ b/Sources/SwiftSyntaxBuilder/generated/SyntaxExpressibleByStringInterpolationConformances.swift @@ -26,6 +26,8 @@ extension ClosureParameterSyntax: SyntaxExpressibleByStringInterpolation {} extension CodeBlockItemSyntax: SyntaxExpressibleByStringInterpolation {} +extension CodeBlockSyntax: SyntaxExpressibleByStringInterpolation {} + extension DeclSyntax: SyntaxExpressibleByStringInterpolation {} extension EnumCaseParameterSyntax: SyntaxExpressibleByStringInterpolation {}