@@ -101,8 +101,17 @@ let defaultAvailableAttr = "@available(SwiftStdlib 5.7, *)"
101
101
@main
102
102
struct VariadicsGenerator : ParsableCommand {
103
103
@Option ( help: " The maximum arity of declarations to generate. " )
104
- var maxArity : Int
104
+ var maxArity : Int = 10
105
+
106
+ @Flag ( help: " Suppress status messages while generating. " )
107
+ var silent : Bool = false
105
108
109
+ func log( _ message: String , terminator: String = " \n " ) {
110
+ if !silent {
111
+ print ( message, terminator: terminator, to: & standardError)
112
+ }
113
+ }
114
+
106
115
func run( ) throws {
107
116
precondition ( maxArity > 1 )
108
117
precondition ( maxArity < Counter . bitWidth)
@@ -126,14 +135,12 @@ struct VariadicsGenerator: ParsableCommand {
126
135
127
136
""" )
128
137
129
- print ( " Generating concatenation overloads... " , to : & standardError )
138
+ log ( " Generating concatenation overloads... " )
130
139
for (leftArity, rightArity) in Permutations ( totalArity: maxArity) {
131
140
guard rightArity != 0 else {
132
141
continue
133
142
}
134
- print (
135
- " Left arity: \( leftArity) Right arity: \( rightArity) " ,
136
- to: & standardError)
143
+ log ( " Left arity: \( leftArity) Right arity: \( rightArity) " )
137
144
emitConcatenation ( leftArity: leftArity, rightArity: rightArity)
138
145
}
139
146
@@ -143,50 +150,48 @@ struct VariadicsGenerator: ParsableCommand {
143
150
144
151
output ( " \n \n " )
145
152
146
- print ( " Generating quantifiers... " , to : & standardError )
153
+ log ( " Generating quantifiers... " )
147
154
for arity in 0 ... maxArity {
148
- print ( " Arity \( arity) : " , terminator: " " , to : & standardError )
155
+ log ( " Arity \( arity) : " , terminator: " " )
149
156
for kind in QuantifierKind . allCases {
150
- print ( " \( kind. rawValue) " , terminator: " " , to : & standardError )
157
+ log ( " \( kind. rawValue) " , terminator: " " )
151
158
emitQuantifier ( kind: kind, arity: arity)
152
159
}
153
- print ( " repeating " , terminator: " " , to : & standardError )
160
+ log ( " repeating " , terminator: " " )
154
161
emitRepeating ( arity: arity)
155
- print ( to : & standardError )
162
+ log ( " " )
156
163
}
157
164
158
- print ( " Generating atomic groups... " , to : & standardError )
165
+ log ( " Generating atomic groups... " )
159
166
for arity in 0 ... maxArity {
160
- print ( " Arity \( arity) : " , terminator: " " , to : & standardError )
167
+ log ( " Arity \( arity) : " , terminator: " " )
161
168
emitAtomicGroup ( arity: arity)
162
- print ( to : & standardError )
169
+ log ( " " )
163
170
}
164
171
165
- print ( " Generating alternation overloads... " , to : & standardError )
172
+ log ( " Generating alternation overloads... " )
166
173
for (leftArity, rightArity) in Permutations ( totalArity: maxArity) {
167
- print (
168
- " Left arity: \( leftArity) Right arity: \( rightArity) " ,
169
- to: & standardError)
174
+ log ( " Left arity: \( leftArity) Right arity: \( rightArity) " )
170
175
emitAlternation ( leftArity: leftArity, rightArity: rightArity)
171
176
}
172
177
173
- print ( " Generating 'AlternationBuilder.buildBlock(_:)' overloads... " , to : & standardError )
178
+ log ( " Generating 'AlternationBuilder.buildBlock(_:)' overloads... " )
174
179
for arity in 1 ... maxArity {
175
- print ( " Capture arity: \( arity) " , to : & standardError )
180
+ log ( " Capture arity: \( arity) " )
176
181
emitUnaryAlternationBuildBlock ( arity: arity)
177
182
}
178
183
179
- print ( " Generating 'capture' and 'tryCapture' overloads... " , to : & standardError )
184
+ log ( " Generating 'capture' and 'tryCapture' overloads... " )
180
185
for arity in 0 ... maxArity {
181
- print ( " Capture arity: \( arity) " , to : & standardError )
186
+ log ( " Capture arity: \( arity) " )
182
187
emitCapture ( arity: arity)
183
188
}
184
189
185
190
output ( " \n \n " )
186
191
187
192
output ( " // END AUTO-GENERATED CONTENT \n " )
188
193
189
- print ( " Done! " , to : & standardError )
194
+ log ( " Done! " )
190
195
}
191
196
192
197
func tupleType( arity: Int , genericParameters: ( ) -> String ) -> String {
0 commit comments