File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Sources/SwiftSyntaxBuilderGeneration Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ class Node {
22
22
let baseKind : String
23
23
let traits : [ String ]
24
24
let children : [ Child ]
25
+ let nonGarbageChildren : [ Child ]
25
26
let collectionElementName : String ?
26
27
let collectionElementChoices : [ String ] ?
27
28
let omitWhenEmpty : Bool
@@ -84,9 +85,34 @@ class Node {
84
85
self . description = description
85
86
86
87
self . traits = traits
87
- self . children = children
88
88
self . baseKind = kind
89
89
90
+ if kind == " SyntaxCollection " {
91
+ self . children = children
92
+ } else {
93
+ // Add implicitly generated GarbageNodes children between
94
+ // any two defined children
95
+ self . children = children. enumerated ( ) . flatMap { ( i, child) in
96
+ let garbageName : String
97
+ if i == 0 {
98
+ garbageName = " GarbageBefore \( child. name) "
99
+ } else {
100
+ garbageName = " GarbageBetween \( children [ i - 1 ] . name) And \( child. name) "
101
+ }
102
+ return [
103
+ Child (
104
+ name: garbageName,
105
+ kind: " GarbageNodes " ,
106
+ isOptional: true ,
107
+ collectionElementName: garbageName
108
+ ) ,
109
+ child,
110
+ ]
111
+ }
112
+ }
113
+
114
+ self . nonGarbageChildren = children. filter { !$0. isGarbageNodes }
115
+
90
116
if !SYNTAX_BASE_KINDS. contains ( baseKind) {
91
117
fatalError ( " unknown base kind ' \( baseKind) ' for node ' \( syntaxKind) ' " )
92
118
}
You can’t perform that action at this time.
0 commit comments