@@ -83,13 +83,21 @@ class VerifyRoundTrip: ParsableCommand {
83
83
abstract: " Verify that printing the parsed syntax tree produces the original source "
84
84
)
85
85
86
- init ( sourceFile: String ? ) {
86
+ init ( sourceFile: String ? , swiftVersion : String ? , enableBareSlashRegex : Bool ? ) {
87
87
self . sourceFile = sourceFile
88
+ self . swiftVersion = swiftVersion
89
+ self . enableBareSlashRegex = enableBareSlashRegex
88
90
}
89
91
90
92
@Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
91
93
var sourceFile : String ?
92
94
95
+ @Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
96
+ var swiftVersion : String ?
97
+
98
+ @Option ( name: . long, help: " Enable or disable the use of forward slash regular-expression literal syntax " )
99
+ var enableBareSlashRegex : Bool ?
100
+
93
101
@Flag ( name: . long, help: " Perform sequence folding with the standard operators " )
94
102
var foldSequences : Bool = false
95
103
@@ -109,15 +117,22 @@ class VerifyRoundTrip: ParsableCommand {
109
117
110
118
try source. withUnsafeBufferPointer { sourceBuffer in
111
119
try Self . run (
112
- source: sourceBuffer, foldSequences: foldSequences
120
+ source: sourceBuffer, swiftVersion: swiftVersion,
121
+ enableBareSlashRegex: enableBareSlashRegex,
122
+ foldSequences: foldSequences
113
123
)
114
124
}
115
125
}
116
126
117
127
static func run(
118
- source: UnsafeBufferPointer < UInt8 > , foldSequences: Bool
128
+ source: UnsafeBufferPointer < UInt8 > , swiftVersion: String ? ,
129
+ enableBareSlashRegex: Bool ? , foldSequences: Bool
119
130
) throws {
120
- let tree = Parser . parse ( source: source)
131
+ let tree = try Parser . parse (
132
+ source: source,
133
+ languageVersion: swiftVersion,
134
+ enableBareSlashRegexLiteral: enableBareSlashRegex
135
+ )
121
136
122
137
let resultTree : Syntax
123
138
if foldSequences {
@@ -143,14 +158,24 @@ class PrintDiags: ParsableCommand {
143
158
@Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
144
159
var sourceFile : String ?
145
160
161
+ @Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
162
+ var swiftVersion : String ?
163
+
164
+ @Option ( name: . long, help: " Enable or disable the use of forward slash regular-expression literal syntax " )
165
+ var enableBareSlashRegex : Bool ?
166
+
146
167
@Flag ( name: . long, help: " Perform sequence folding with the standard operators " )
147
168
var foldSequences : Bool = false
148
169
149
170
func run( ) throws {
150
171
let source = try getContentsOfSourceFile ( at: sourceFile)
151
172
152
- source. withUnsafeBufferPointer { sourceBuffer in
153
- let tree = Parser . parse ( source: sourceBuffer)
173
+ try source. withUnsafeBufferPointer { sourceBuffer in
174
+ let tree = try Parser . parse (
175
+ source: sourceBuffer,
176
+ languageVersion: swiftVersion,
177
+ enableBareSlashRegexLiteral: enableBareSlashRegex
178
+ )
154
179
155
180
var diags = ParseDiagnosticsGenerator . diagnostics ( for: tree)
156
181
print ( DiagnosticsFormatter . annotatedSource ( tree: tree, diags: diags) )
@@ -177,14 +202,24 @@ class PrintInitCall: ParsableCommand {
177
202
@Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
178
203
var sourceFile : String ?
179
204
205
+ @Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
206
+ var swiftVersion : String ?
207
+
208
+ @Option ( name: . long, help: " Enable or disable the use of forward slash regular-expression literal syntax " )
209
+ var enableBareSlashRegex : Bool ?
210
+
180
211
@Flag ( name: . long, help: " Perform sequence folding with the standard operators " )
181
212
var foldSequences : Bool = false
182
213
183
214
func run( ) throws {
184
215
let source = try getContentsOfSourceFile ( at: sourceFile)
185
216
186
- source. withUnsafeBufferPointer { sourceBuffer in
187
- var tree = Parser . parse ( source: sourceBuffer)
217
+ try source. withUnsafeBufferPointer { sourceBuffer in
218
+ var tree = try Parser . parse (
219
+ source: sourceBuffer,
220
+ languageVersion: swiftVersion,
221
+ enableBareSlashRegexLiteral: enableBareSlashRegex
222
+ )
188
223
189
224
if foldSequences {
190
225
tree = foldAllSequences ( tree) . 0 . as ( SourceFileSyntax . self) !
@@ -206,14 +241,24 @@ class PrintTree: ParsableCommand {
206
241
@Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
207
242
var sourceFile : String ?
208
243
244
+ @Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
245
+ var swiftVersion : String ?
246
+
247
+ @Option ( name: . long, help: " Enable or disable the use of forward slash regular-expression literal syntax " )
248
+ var enableBareSlashRegex : Bool ?
249
+
209
250
@Flag ( name: . long, help: " Perform sequence folding with the standard operators " )
210
251
var foldSequences : Bool = false
211
252
212
253
func run( ) throws {
213
254
let source = try getContentsOfSourceFile ( at: sourceFile)
214
255
215
- source. withUnsafeBufferPointer { sourceBuffer in
216
- let tree = Parser . parse ( source: sourceBuffer)
256
+ try source. withUnsafeBufferPointer { sourceBuffer in
257
+ let tree = try Parser . parse (
258
+ source: sourceBuffer,
259
+ languageVersion: swiftVersion,
260
+ enableBareSlashRegexLiteral: enableBareSlashRegex
261
+ )
217
262
218
263
let resultTree : Syntax
219
264
if foldSequences {
@@ -238,6 +283,12 @@ class Reduce: ParsableCommand {
238
283
@Argument ( help: " The test case that should be reduced; if omitted, use stdin " )
239
284
var sourceFile : String ?
240
285
286
+ @Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
287
+ var swiftVersion : String ?
288
+
289
+ @Option ( name: . long, help: " Enable or disable the use of forward slash regular-expression literal syntax " )
290
+ var enableBareSlashRegex : Bool ?
291
+
241
292
@Flag ( name: . long, help: " Perform sequence folding with the standard operators " )
242
293
var foldSequences : Bool = false
243
294
@@ -275,6 +326,16 @@ class Reduce: ParsableCommand {
275
326
process. arguments = [
276
327
" verify-round-trip " , tempFileURL. path,
277
328
]
329
+ if let enableBareSlashRegex = enableBareSlashRegex {
330
+ process. arguments! += [
331
+ " --enable-bare-slash-regex " , enableBareSlashRegex ? " true " : " false "
332
+ ]
333
+ }
334
+ if let swiftVersion = swiftVersion {
335
+ process. arguments! += [
336
+ " --swift-version " , swiftVersion
337
+ ]
338
+ }
278
339
if foldSequences {
279
340
process. arguments! += [ " --fold-sequences " ]
280
341
}
@@ -311,8 +372,8 @@ class Reduce: ParsableCommand {
311
372
private func runVerifyRoundTripInCurrentProcess( source: [ UInt8 ] ) throws -> Bool {
312
373
do {
313
374
try source. withUnsafeBufferPointer { sourceBuffer in
314
- try VerifyRoundTrip . run (
315
- source : sourceBuffer , foldSequences: foldSequences)
375
+ try VerifyRoundTrip . run ( source : sourceBuffer , swiftVersion : self . swiftVersion , enableBareSlashRegex : self . enableBareSlashRegex ,
376
+ foldSequences: foldSequences)
316
377
}
317
378
} catch {
318
379
return false
0 commit comments