@@ -44,7 +44,8 @@ extension DSLTree {
4444
4545 /// Marks all captures in a subpattern as ignored in strongly-typed output.
4646 case ignoreCapturesInTypedOutput( Node )
47-
47+ case limitCaptureNesting( Node )
48+
4849 // TODO: Consider splitting off grouped conditions, or have
4950 // our own kind
5051
@@ -79,13 +80,6 @@ extension DSLTree {
7980 /// TODO: Consider splitting off expression functions, or have our own kind
8081 case absentFunction( _AST . AbsentFunction )
8182
82- // MARK: - Tree conversions
83-
84- /// The target of AST conversion.
85- ///
86- /// Keeps original AST around for rich syntactic and source information
87- case convertedRegexLiteral( Node , _AST . ASTNode )
88-
8983 // MARK: - Extensibility points
9084
9185 case consumer( _ConsumerInterface )
@@ -384,8 +378,9 @@ extension DSLTree.Node {
384378 case . orderedChoice( let c) , . concatenation( let c) :
385379 return !c. isEmpty
386380
387- case . convertedRegexLiteral, . capture, . nonCapturingGroup,
388- . quantification, . ignoreCapturesInTypedOutput, . conditional:
381+ case . capture, . nonCapturingGroup,
382+ . quantification, . ignoreCapturesInTypedOutput, . limitCaptureNesting,
383+ . conditional:
389384 return true
390385
391386 case . absentFunction( let abs) :
@@ -400,14 +395,14 @@ extension DSLTree.Node {
400395 case let . orderedChoice( v) : return v
401396 case let . concatenation( v) : return v
402397
403- case let . convertedRegexLiteral( n, _) :
404- // Treat this transparently
405- return n. children
406-
407398 case let . capture( _, _, n, _) : return [ n]
408399 case let . nonCapturingGroup( _, n) : return [ n]
409400 case let . quantification( _, _, n) : return [ n]
410- case let . ignoreCapturesInTypedOutput( n) : return [ n]
401+ case let . ignoreCapturesInTypedOutput( n) : return [ n]
402+
403+ case let . limitCaptureNesting( n) :
404+ // This is a transparent wrapper
405+ return n. children
411406
412407 case let . conditional( _, t, f) : return [ t, f]
413408
@@ -424,18 +419,12 @@ extension DSLTree.Node {
424419
425420extension DSLTree . Node {
426421 var astNode : AST . Node ? {
427- switch self {
428- case let . convertedRegexLiteral( _, literal) : return literal. ast
429- default : return nil
430- }
422+ nil
431423 }
432424
433425 /// If this node is for a converted literal, look through it.
434426 var lookingThroughConvertedLiteral : Self {
435- switch self {
436- case let . convertedRegexLiteral( n, _) : return n
437- default : return self
438- }
427+ self
439428 }
440429}
441430
@@ -468,10 +457,6 @@ extension DSLTree.Node {
468457 switch self {
469458 case . capture:
470459 return true
471- case let . convertedRegexLiteral( n, re) :
472- assert ( n. hasCapture == re. ast. hasCapture)
473- return n. hasCapture
474-
475460 default :
476461 return self . children. any ( \. hasCapture)
477462 }
@@ -655,6 +640,9 @@ extension CaptureList.Builder {
655640 case let . ignoreCapturesInTypedOutput( child) :
656641 addCaptures ( of: child, optionalNesting: nesting, visibleInTypedOutput: false )
657642
643+ case let . limitCaptureNesting( child) :
644+ addCaptures ( of: child, optionalNesting: nesting. disablingNesting, visibleInTypedOutput: visibleInTypedOutput)
645+
658646 case let . conditional( cond, trueBranch, falseBranch) :
659647 switch cond. ast {
660648 case . group( let g) :
@@ -685,11 +673,11 @@ extension CaptureList.Builder {
685673 #endif
686674 }
687675
688- case let . convertedRegexLiteral( n, _) :
689- // We disable nesting for converted AST trees, as literals do not nest
690- // captures. This includes literals nested in a DSL.
691- return addCaptures ( of: n, optionalNesting: nesting. disablingNesting, visibleInTypedOutput: visibleInTypedOutput)
692-
676+ // case let .convertedRegexLiteral(n, _):
677+ // // We disable nesting for converted AST trees, as literals do not nest
678+ // // captures. This includes literals nested in a DSL.
679+ // return addCaptures(of: n, optionalNesting: nesting.disablingNesting, visibleInTypedOutput: visibleInTypedOutput)
680+ //
693681 case . matcher:
694682 break
695683
@@ -717,8 +705,8 @@ extension DSLTree.Node {
717705 return true
718706 case . orderedChoice, . concatenation, . capture,
719707 . conditional, . quantification, . customCharacterClass, . atom,
720- . trivia, . empty, . quotedLiteral, . absentFunction ,
721- . convertedRegexLiteral , . consumer ,
708+ . trivia, . empty, . quotedLiteral, . limitCaptureNesting ,
709+ . consumer , . absentFunction ,
722710 . characterPredicate, . matcher:
723711 return false
724712 }
@@ -805,8 +793,7 @@ extension DSLTree.Node {
805793 options. beginScope ( )
806794 defer { options. endScope ( ) }
807795 return child. _canOnlyMatchAtStartImpl ( & options)
808- case . ignoreCapturesInTypedOutput( let child) ,
809- . convertedRegexLiteral( let child, _) :
796+ case . ignoreCapturesInTypedOutput( let child) , . limitCaptureNesting( let child) :
810797 return child. _canOnlyMatchAtStartImpl ( & options)
811798
812799 // A quantification that doesn't require its child to exist can still
@@ -869,14 +856,13 @@ extension DSLTree {
869856 case let . orderedChoice( v) : return v. map ( _Tree. init)
870857 case let . concatenation( v) : return v. map ( _Tree. init)
871858
872- case let . convertedRegexLiteral( n, _) :
873- // Treat this transparently
874- return _Tree ( n) . children
875-
876859 case let . capture( _, _, n, _) : return [ _Tree ( n) ]
877860 case let . nonCapturingGroup( _, n) : return [ _Tree ( n) ]
878861 case let . quantification( _, _, n) : return [ _Tree ( n) ]
879- case let . ignoreCapturesInTypedOutput( n) : return [ _Tree ( n) ]
862+ case let . ignoreCapturesInTypedOutput( n) : return [ _Tree ( n) ]
863+ case let . limitCaptureNesting( n) :
864+ // This is a transparent wrapper
865+ return _Tree ( n) . children
880866
881867 case let . conditional( _, t, f) : return [ _Tree ( t) , _Tree ( f) ]
882868
0 commit comments