@@ -169,7 +169,7 @@ func f() {
169
169
let x = /a/
170
170
171
171
// Slashes can be escaped.
172
- let x = /\/ /
172
+ let x = /\/ + /
173
173
174
174
// Slashes must be escaped in character classes.
175
175
let x = /[/ + " ]/ + // "
@@ -217,18 +217,18 @@ func f() {
217
217
218
218
// Regexes without extended delimiters cannot be preceded by infix
219
219
// operators without whitespaces.
220
- // `a`, infix operator `+/`, `b`, and infix operator `/`
221
- let x = a+/ b /
220
+ // `a`, infix operator `+/`, `b`, and infix operator `% /`
221
+ let x = a+/ b % /
222
222
c ( )
223
223
224
224
// Regexes without extended delimiters can be preceded by infix operators
225
225
// with whitespaces.
226
- // `a`, infix operator `+`, and regex /b /
227
- let x = a + / b /
226
+ // `a`, infix operator `+`, and regex /b % /
227
+ let x = a + /b % /
228
228
c ( )
229
229
230
230
// Comments are whitespaces.
231
- let x = a/**/+/**// b /
231
+ let x = a/**/+/**// b % /
232
232
c ( )
233
233
234
234
// Regexes with extended delimiters can be preceded by infix operators
@@ -240,26 +240,42 @@ func f() {
240
240
// Regexes without extended delimiters cannot start with spaces.
241
241
let regex = Regex {
242
242
digit
243
- / [ +- ] /
243
+ // infix operator `/`, and `a` with postfix operator `/'
244
+ / a/
245
+ digit
246
+ }
247
+ // Regexes without extended delimiters cannot end with spaces.
248
+ let regex = Regex {
249
+ digit
250
+ // prefix operator `/`, `a`, and infix operator `/'
251
+ / a /
244
252
digit
245
253
}
246
254
let regex = Regex {
247
255
digit
248
- / [ +- ] /
256
+ // regex /a/
257
+ / a/
249
258
digit
250
259
}
251
260
252
261
// Initial space must be escaped.
253
262
let regex = Regex {
254
263
digit
255
- / \ [ +-] /
264
+ / \ a /
265
+ digit
266
+ }
267
+
268
+ // Final space must be escaped.
269
+ let regex = Regex {
270
+ digit
271
+ / a\ /
256
272
digit
257
273
}
258
274
259
275
// Regexes with extended delimiters can start with spaces.
260
276
let regex = Regex {
261
277
digit
262
- #/ [+-] /#
278
+ #/ a /#
263
279
digit
264
280
}
265
281
@@ -291,39 +307,39 @@ func f() {
291
307
c( )
292
308
293
309
// Regexes can be preceded with prefix operators wihtout spaces.
294
- // prefix operator `+` and regex /a /.
295
- let x = +/ a /
310
+ // prefix operator `+` and regex /a % /.
311
+ let x = +/ a % /
296
312
b ( )
297
313
298
314
// Regexes without extended delimiters cannot contain unmatching close
299
315
// parentheses.
300
- array. reduce ( 1 , / ) { otherArray. reduce ( 1 , / )
301
- array. reduce ( 1 , / ) } ; otherArray. reduce ( 1 , / )
316
+ array. reduce ( 1 , /) { otherArray.reduce(1,/ )
317
+ array. reduce ( 1 , /) }; otherArray.reduce(1,/ )
302
318
303
319
// Regexes without extended delimiters can contain matching close
304
320
// parentheses.
305
- array . reduce ( 1 , / ( a) { otherArray. reduce ( 1 , / )
306
- array. reduce ( 1 , / ( a) } ; otherArray. reduce ( 1 , / )
321
+ array. reduce ( 1 , /(a) { otherArray.reduce(1,/ )
322
+ array. reduce ( 1 , /(a) }; otherArray.reduce(1,/ )
307
323
308
324
// Regexes without extended delimiters can contain escaped close
309
325
// parentheses.
310
- array. reduce ( 1 , / \) { otherArray. reduce ( 1 , / )
311
- array. reduce ( 1 , / \) } ; otherArray. reduce ( 1 , / )
326
+ array. reduce ( 1 , /\) { otherArray.reduce(1,/ )
327
+ array. reduce ( 1 , /\) }; otherArray.reduce(1,/ )
312
328
313
329
// Character classes can contain closing parentheses.
314
- array . reduce ( 1 , / [ ) ] { otherArray. reduce ( 1 , / )
315
- array. reduce ( 1 , / [ ) ] } ; otherArray. reduce ( 1 , / )
330
+ array. reduce ( 1 , /[)] { otherArray.reduce(1,/ )
331
+ array. reduce ( 1 , /[)] }; otherArray.reduce(1,/ )
316
332
317
333
// Regexes with extended delimiters can contain unmatching close
318
334
// parentheses.
319
- array. reduce ( 1 , #/) { otherArray.reduce(1, /# )
320
- array. reduce ( 1 , #/) }; otherArray.reduce(1, /# )
335
+ array. reduce ( 1 , #/) { otherArray.reduce(1,/# )
336
+ array. reduce ( 1 , #/) }; otherArray.reduce(1,/# )
321
337
322
338
323
339
// Regexes can contain unmatching close square brackets.
324
- let d = a [ / ] /
340
+ let d = a [ /] % /
325
341
]
326
- let d = a [ ( / ) ] /
342
+ let d = a[ ( /)] % /
327
343
b ( )
328
344
329
345
// Comments have higher precedence.
0 commit comments