@@ -74,6 +74,51 @@ extension PrettyPrinter {
74
74
printBlock ( " Regex " ) { printer in
75
75
printer. printAsPattern ( convertedFromAST: node, isTopLevel: true )
76
76
}
77
+
78
+ printInlineMatchingOptions ( )
79
+ }
80
+
81
+ mutating func printInlineMatchingOptions( ) {
82
+ for matchingOptions in inlineMatchingOptions {
83
+ let options = popMatchingOptions ( )
84
+
85
+ printIndented { printer in
86
+ for option in options {
87
+ switch option. kind {
88
+ case . asciiOnlyDigit:
89
+ printer. print ( " .asciiOnlyDigits() " )
90
+
91
+ case . asciiOnlyPOSIXProps:
92
+ printer. print ( " .asciiOnlyCharacterClasses() " )
93
+
94
+ case . asciiOnlySpace:
95
+ printer. print ( " .asciiOnlyWhitespace() " )
96
+
97
+ case . asciiOnlyWord:
98
+ printer. print ( " .asciiOnlyWordCharacters() " )
99
+
100
+ case . caseInsensitive:
101
+ printer. print ( " .ignoresCase() " )
102
+
103
+ case . multiline:
104
+ printer. print ( " .anchorsMatchLineEndings() " )
105
+
106
+ case . reluctantByDefault:
107
+ // This is handled by altering every OneOrMore, etc by changing each
108
+ // individual repetition behavior instead of creating a nested regex.
109
+ continue
110
+
111
+ case . singleLine:
112
+ printer. print ( " .dotMatchesNewlines() " )
113
+
114
+ default :
115
+ break
116
+ }
117
+ }
118
+ }
119
+
120
+ print ( " } " )
121
+ }
77
122
}
78
123
79
124
// FIXME: Use of back-offs like height and depth
@@ -424,7 +469,7 @@ extension PrettyPrinter {
424
469
// Also in the same vein, if we have a few atom members but no
425
470
// nonAtomMembers, then we can emit a single .anyOf(...) for them.
426
471
if !charMembers. isEmpty, nonCharMembers. isEmpty {
427
- let anyOf = " .anyOf( \( charMembers) ) "
472
+ let anyOf = " CharacterClass .anyOf(\( charMembers) ) "
428
473
429
474
indent ( )
430
475
@@ -502,15 +547,15 @@ extension PrettyPrinter {
502
547
if wrap {
503
548
output ( " One(.anyOf( \( String ( c) . _quoted) )) " )
504
549
} else {
505
- output ( " .anyOf( \( String ( c) . _quoted) ) " )
550
+ output ( " CharacterClass .anyOf(\( String ( c) . _quoted) ) " )
506
551
}
507
552
508
553
case let . scalar( s) :
509
554
510
555
if wrap {
511
556
output ( " One(.anyOf( \( s. _dslBase. _bareQuoted) )) " )
512
557
} else {
513
- output ( " .anyOf( \( s. _dslBase. _bareQuoted) ) " )
558
+ output ( " CharacterClass .anyOf(\( s. _dslBase. _bareQuoted) ) " )
514
559
}
515
560
516
561
case let . unconverted( a) :
@@ -538,7 +583,7 @@ extension PrettyPrinter {
538
583
if wrap {
539
584
output ( " One(.anyOf( \( s. _quoted) )) " )
540
585
} else {
541
- output ( " .anyOf( \( s. _quoted) ) " )
586
+ output ( " CharacterClass .anyOf(\( s. _quoted) ) " )
542
587
}
543
588
544
589
case . trivia( _) :
@@ -1285,10 +1330,20 @@ extension DSLTree.Atom {
1285
1330
switch add. kind {
1286
1331
case . reluctantByDefault:
1287
1332
printer. quantificationBehavior = . reluctant
1333
+
1334
+ // Don't create a nested Regex for (?U), we handle this by altering
1335
+ // every individual repetitionBehavior for things like OneOrMore.
1336
+ if matchingOptions. ast. adding. count == 1 {
1337
+ return nil
1338
+ }
1339
+
1288
1340
default :
1289
1341
break
1290
1342
}
1291
1343
}
1344
+
1345
+ printer. print ( " Regex { " )
1346
+ printer. pushMatchingOptions ( matchingOptions. ast. adding)
1292
1347
}
1293
1348
1294
1349
return nil
0 commit comments