Skip to content

Commit d1e6aa5

Browse files
committed
Add parserFunction for CodeBlockItem node in CodeGeneration
1 parent 84d3251 commit d1e6aa5

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public let COMMON_NODES: [Node] = [
2626
nameForDiagnostics: nil,
2727
description: "A CodeBlockItem is any Syntax node that appears on its own line inside a CodeBlock.",
2828
kind: "Syntax",
29+
parserFunction: "parseCodeBlockItem",
2930
children: [
3031
Child(
3132
name: "Item",

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,34 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(fo
5959

6060
for node in SYNTAX_NODES {
6161
if let parserFunction = node.parserFunction {
62-
DeclSyntax(
63-
"""
64-
extension \(raw: node.name): SyntaxParseable {
65-
public static func parse(from parser: inout Parser) -> Self {
66-
let node = parser.\(raw: parserFunction)()
67-
let raw = RawSyntax(parser.parseRemainder(into: node))
68-
return Syntax(raw: raw).cast(Self.self)
62+
if node.syntaxKind == "CodeBlockItem" {
63+
DeclSyntax(
64+
"""
65+
extension \(raw: node.name): SyntaxParseable {
66+
public static func parse(from parser: inout Parser) -> Self {
67+
guard let node = parser.parseCodeBlockItem() else {
68+
assertionFailure("Invalid code block item")
69+
return Syntax(raw: RawSyntax(parser.parseCodeBlockItem()!)).cast(Self.self)
70+
}
71+
let raw = RawSyntax(parser.parseRemainder(into: node))
72+
return Syntax(raw: raw).cast(Self.self)
73+
}
6974
}
70-
}
71-
"""
72-
)
75+
"""
76+
)
77+
} else {
78+
DeclSyntax(
79+
"""
80+
extension \(raw: node.name): SyntaxParseable {
81+
public static func parse(from parser: inout Parser) -> Self {
82+
let node = parser.\(raw: parserFunction)()
83+
let raw = RawSyntax(parser.parseRemainder(into: node))
84+
return Syntax(raw: raw).cast(Self.self)
85+
}
86+
}
87+
"""
88+
)
89+
}
7390
}
7491
}
7592

0 commit comments

Comments
 (0)