Skip to content

Make CodeBlockSyntax parseable #2361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public let COMMON_NODES: [Node] = [
kind: .codeBlock,
base: .syntax,
nameForDiagnostics: "code block",
parserFunction: "parseCodeBlock",
traits: [
"Braced",
"WithStatements",
Expand Down
18 changes: 18 additions & 0 deletions Sources/SwiftParser/generated/LayoutNodes+Parsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extension ClosureParameterSyntax: SyntaxExpressibleByStringInterpolation {}

extension CodeBlockItemSyntax: SyntaxExpressibleByStringInterpolation {}

extension CodeBlockSyntax: SyntaxExpressibleByStringInterpolation {}

extension DeclSyntax: SyntaxExpressibleByStringInterpolation {}

extension EnumCaseParameterSyntax: SyntaxExpressibleByStringInterpolation {}
Expand Down