File tree Expand file tree Collapse file tree 2 files changed +28
-10
lines changed
generate-swiftsyntax/templates/swiftparser Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public let COMMON_NODES: [Node] = [
26
26
nameForDiagnostics: nil ,
27
27
description: " A CodeBlockItem is any Syntax node that appears on its own line inside a CodeBlock. " ,
28
28
kind: " Syntax " ,
29
+ parserFunction: " parseCodeBlockItem " ,
29
30
children: [
30
31
Child (
31
32
name: " Item " ,
Original file line number Diff line number Diff line change @@ -59,17 +59,34 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: generateCopyrightHeader(fo
59
59
60
60
for node in SYNTAX_NODES {
61
61
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
+ }
69
74
}
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
+ }
73
90
}
74
91
}
75
92
You can’t perform that action at this time.
0 commit comments