@@ -74,6 +74,51 @@ extension PrettyPrinter {
7474 printBlock ( " Regex " ) { printer in
7575 printer. printAsPattern ( convertedFromAST: node, isTopLevel: true )
7676 }
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+ }
77122 }
78123
79124 // FIXME: Use of back-offs like height and depth
@@ -424,7 +469,7 @@ extension PrettyPrinter {
424469 // Also in the same vein, if we have a few atom members but no
425470 // nonAtomMembers, then we can emit a single .anyOf(...) for them.
426471 if !charMembers. isEmpty, nonCharMembers. isEmpty {
427- let anyOf = " .anyOf( \( charMembers) ) "
472+ let anyOf = " CharacterClass .anyOf(\( charMembers) ) "
428473
429474 indent ( )
430475
@@ -502,15 +547,15 @@ extension PrettyPrinter {
502547 if wrap {
503548 output ( " One(.anyOf( \( String ( c) . _quoted) )) " )
504549 } else {
505- output ( " .anyOf( \( String ( c) . _quoted) ) " )
550+ output ( " CharacterClass .anyOf(\( String ( c) . _quoted) ) " )
506551 }
507552
508553 case let . scalar( s) :
509554
510555 if wrap {
511556 output ( " One(.anyOf( \( s. _dslBase. _bareQuoted) )) " )
512557 } else {
513- output ( " .anyOf( \( s. _dslBase. _bareQuoted) ) " )
558+ output ( " CharacterClass .anyOf(\( s. _dslBase. _bareQuoted) ) " )
514559 }
515560
516561 case let . unconverted( a) :
@@ -538,7 +583,7 @@ extension PrettyPrinter {
538583 if wrap {
539584 output ( " One(.anyOf( \( s. _quoted) )) " )
540585 } else {
541- output ( " .anyOf( \( s. _quoted) ) " )
586+ output ( " CharacterClass .anyOf(\( s. _quoted) ) " )
542587 }
543588
544589 case . trivia( _) :
@@ -1285,10 +1330,20 @@ extension DSLTree.Atom {
12851330 switch add. kind {
12861331 case . reluctantByDefault:
12871332 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+
12881340 default :
12891341 break
12901342 }
12911343 }
1344+
1345+ printer. print ( " Regex { " )
1346+ printer. pushMatchingOptions ( matchingOptions. ast. adding)
12921347 }
12931348
12941349 return nil
0 commit comments