1231 references to RegexNodeKind
System.Text.RegularExpressions.Generator (1231)
parent\src\System\Text\RegularExpressions\RegexFindOptimizations.cs (18)
56
if (rightToLeft && LeadingAnchor ==
RegexNodeKind
.Bol)
59
LeadingAnchor =
RegexNodeKind
.Unknown;
61
if (LeadingAnchor is
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
RegexNodeKind
.EndZ or
RegexNodeKind
.End)
65
(
RegexNodeKind
.Beginning, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_Beginning,
66
(
RegexNodeKind
.Beginning, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_Beginning,
67
(
RegexNodeKind
.Start, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_Start,
68
(
RegexNodeKind
.Start, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_Start,
69
(
RegexNodeKind
.End, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_End,
70
(
RegexNodeKind
.End, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_End,
83
if (TrailingAnchor is
RegexNodeKind
.End or
RegexNodeKind
.EndZ &&
90
FindMode = TrailingAnchor ==
RegexNodeKind
.End ?
280
LeadingAnchor ==
RegexNodeKind
.Bol; // there's a leading BOL anchor we can otherwise search for
286
public
RegexNodeKind
LeadingAnchor { get; private set; }
289
public
RegexNodeKind
TrailingAnchor { get; }
parent\src\System\Text\RegularExpressions\RegexNode.cs (675)
23
public
RegexNodeKind
Kind { get; private set; }
51
public RegexNode(
RegexNodeKind
kind, RegexOptions options)
57
public RegexNode(
RegexNodeKind
kind, RegexOptions options, char ch)
64
public RegexNode(
RegexNodeKind
kind, RegexOptions options, string str)
71
public RegexNode(
RegexNodeKind
kind, RegexOptions options, int m)
78
public RegexNode(
RegexNodeKind
kind, RegexOptions options, int m, int n)
89
Debug.Assert(Kind is
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
90
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
91
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic);
121
return new RegexNode(
RegexNodeKind
.One, options & ~RegexOptions.IgnoreCase, ch);
127
return new RegexNode(
RegexNodeKind
.Set, options & ~RegexOptions.IgnoreCase, stringSet);
131
return new RegexNode(
RegexNodeKind
.One, options, ch);
138
Kind ==
RegexNodeKind
.Concatenate &&
150
private void MakeRep(
RegexNodeKind
kind, int min, int max)
152
Kind += kind -
RegexNodeKind
.One;
169
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop:
172
Kind +=
RegexNodeKind
.Oneloopatomic -
RegexNodeKind
.Oneloop;
175
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy:
179
Kind +=
RegexNodeKind
.Oneloopatomic -
RegexNodeKind
.Onelazy;
189
Kind =
RegexNodeKind
.Empty;
193
else if (Kind ==
RegexNodeKind
.Oneloopatomic && N is >= 2 and <= MultiVsRepeaterLimit)
197
Kind =
RegexNodeKind
.Multi;
204
case
RegexNodeKind
.Loop:
205
if (Parent is not { Kind:
RegexNodeKind
.Atomic })
207
RegexNode loopAsChild = new(
RegexNodeKind
.Loop, Options, M, N);
208
Kind =
RegexNodeKind
.Atomic;
215
case
RegexNodeKind
.Lazyloop:
225
goto case
RegexNodeKind
.Loop;
228
Kind =
RegexNodeKind
.Empty;
372
Debug.Assert(rootNode.Kind ==
RegexNodeKind
.Capture);
429
case
RegexNodeKind
.Atomic:
433
case
RegexNodeKind
.Concatenate:
438
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when node.N == int.MaxValue:
439
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when node.N == int.MaxValue && !atomicByAncestry:
440
if (node.Parent is { Kind:
RegexNodeKind
.Concatenate } parent)
442
parent.InsertChild(1, new RegexNode(
RegexNodeKind
.UpdateBumpalong, node.Options));
523
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop:
524
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy:
530
case
RegexNodeKind
.Atomic:
531
case
RegexNodeKind
.PositiveLookaround:
532
case
RegexNodeKind
.NegativeLookaround:
542
case
RegexNodeKind
.Capture:
543
case
RegexNodeKind
.Concatenate when !rtl:
545
if ((existingChild.Kind is
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop) &&
546
node.Parent is not { Kind:
RegexNodeKind
.Atomic }) // validate grandparent isn't atomic
548
var atomic = new RegexNode(
RegexNodeKind
.Atomic, existingChild.Options);
558
case
RegexNodeKind
.Alternate:
559
case
RegexNodeKind
.BackreferenceConditional:
560
case
RegexNodeKind
.ExpressionConditional:
568
if (node.Kind !=
RegexNodeKind
.ExpressionConditional) // ReduceExpressionConditional will have already applied ending backtracking removal
583
case
RegexNodeKind
.Lazyloop:
584
case
RegexNodeKind
.Loop:
589
Debug.Assert(node.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.Empty or
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
591
if (node.Kind is
RegexNodeKind
.Atomic)
594
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
597
if (node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop)
631
case
RegexNodeKind
.Backreference:
638
RegexNodeKind
.Alternate => ReduceAlternation(),
639
RegexNodeKind
.Atomic => ReduceAtomic(),
640
RegexNodeKind
.Concatenate => ReduceConcatenation(),
641
RegexNodeKind
.Group => ReduceGroup(),
642
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop => ReduceLoops(),
643
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround => ReduceLookaround(),
644
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy => ReduceSet(),
645
RegexNodeKind
.ExpressionConditional => ReduceExpressionConditional(),
646
RegexNodeKind
.BackreferenceConditional => ReduceBackreferenceConditional(),
659
Debug.Assert(Kind is
RegexNodeKind
.Alternate or
RegexNodeKind
.Concatenate);
662
0 => new RegexNode(Kind ==
RegexNodeKind
.Alternate ?
RegexNodeKind
.Nothing :
RegexNodeKind
.Empty, Options),
676
Debug.Assert(Kind ==
RegexNodeKind
.Group);
679
while (u.Kind ==
RegexNodeKind
.Group)
704
Debug.Assert(Kind ==
RegexNodeKind
.Atomic);
709
while (child.Kind ==
RegexNodeKind
.Atomic)
719
case
RegexNodeKind
.Empty:
720
case
RegexNodeKind
.Nothing:
725
case
RegexNodeKind
.One:
726
case
RegexNodeKind
.Notone:
727
case
RegexNodeKind
.Set:
728
case
RegexNodeKind
.Multi:
732
case
RegexNodeKind
.Oneloopatomic:
733
case
RegexNodeKind
.Notoneloopatomic:
734
case
RegexNodeKind
.Setloopatomic:
739
case
RegexNodeKind
.Oneloop:
740
case
RegexNodeKind
.Notoneloop:
741
case
RegexNodeKind
.Setloop:
742
case
RegexNodeKind
.Onelazy:
743
case
RegexNodeKind
.Notonelazy:
744
case
RegexNodeKind
.Setlazy:
750
case
RegexNodeKind
.Alternate:
759
if (branches[0].Kind ==
RegexNodeKind
.Empty)
761
return new RegexNode(
RegexNodeKind
.Empty, child.Options);
770
if (branches[i].Kind ==
RegexNodeKind
.Empty)
851
(child.Child(0).Kind is
RegexNodeKind
.Empty || child.Child(1).Kind is
RegexNodeKind
.Empty); // can be transformed into a ? or ??
866
return child.Kind ==
RegexNodeKind
.Empty ?
881
Debug.Assert(Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
884
RegexNodeKind
kind = Kind;
897
if (kind ==
RegexNodeKind
.Loop)
901
case
RegexNodeKind
.Oneloop:
902
case
RegexNodeKind
.Oneloopatomic:
903
case
RegexNodeKind
.Notoneloop:
904
case
RegexNodeKind
.Notoneloopatomic:
905
case
RegexNodeKind
.Setloop:
906
case
RegexNodeKind
.Setloopatomic:
915
case
RegexNodeKind
.Onelazy:
916
case
RegexNodeKind
.Notonelazy:
917
case
RegexNodeKind
.Setlazy:
951
return new RegexNode(
RegexNodeKind
.Nothing, Options);
962
case
RegexNodeKind
.One:
963
case
RegexNodeKind
.Notone:
964
case
RegexNodeKind
.Set:
965
child.MakeRep(u.Kind ==
RegexNodeKind
.Lazyloop ?
RegexNodeKind
.Onelazy :
RegexNodeKind
.Oneloop, u.M, u.N);
969
case
RegexNodeKind
.Empty:
974
case
RegexNodeKind
.PositiveLookaround when ContainsKind(child, [
RegexNodeKind
.Capture]) is false:
975
case
RegexNodeKind
.NegativeLookaround or
976
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
977
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
978
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
979
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
980
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary:
990
u = u.M == 0 ? new RegexNode(
RegexNodeKind
.Empty, Options) : child;
1013
Debug.Assert(Kind is
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy);
1018
Kind =
RegexNodeKind
.Nothing;
1026
Kind ==
RegexNodeKind
.Set ?
RegexNodeKind
.One :
1027
Kind ==
RegexNodeKind
.Setloop ?
RegexNodeKind
.Oneloop :
1028
Kind ==
RegexNodeKind
.Setloopatomic ?
RegexNodeKind
.Oneloopatomic :
1029
RegexNodeKind
.Onelazy;
1036
Kind ==
RegexNodeKind
.Set ?
RegexNodeKind
.Notone :
1037
Kind ==
RegexNodeKind
.Setloop ?
RegexNodeKind
.Notoneloop :
1038
Kind ==
RegexNodeKind
.Setloopatomic ?
RegexNodeKind
.Notoneloopatomic :
1039
RegexNodeKind
.Notonelazy;
1073
Debug.Assert(Kind ==
RegexNodeKind
.Alternate);
1078
return new RegexNode(
RegexNodeKind
.Nothing, Options);
1086
if (node.Kind ==
RegexNodeKind
.Alternate)
1089
if (node.Kind ==
RegexNodeKind
.Alternate)
1092
if (node.Kind ==
RegexNodeKind
.Alternate)
1100
if (node.Kind is
RegexNodeKind
.Alternate && node.ChildCount() == 2)
1102
if (node.Child(1).Kind is
RegexNodeKind
.Empty)
1106
else if (node.Child(0).Kind is
RegexNodeKind
.Empty)
1143
if (at.Kind ==
RegexNodeKind
.Alternate)
1161
else if (at.Kind is
RegexNodeKind
.Set or
RegexNodeKind
.One)
1166
if (at.Kind ==
RegexNodeKind
.Set)
1190
if (prev.Kind ==
RegexNodeKind
.One)
1200
if (at.Kind ==
RegexNodeKind
.One)
1210
prev.Kind =
RegexNodeKind
.Set;
1217
else if (at.Kind ==
RegexNodeKind
.Nothing)
1241
Debug.Assert(alternation.Kind ==
RegexNodeKind
.Alternate);
1260
RegexNode required = startingNode.Kind ==
RegexNodeKind
.Concatenate ? startingNode.Child(0) : startingNode;
1263
case
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set:
1264
case
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloopatomic:
1265
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when required.M == required.N:
1266
case
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
RegexNodeKind
.Bol
1267
or
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol
1268
or
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary
1269
or
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary:
1281
RegexNode other = endingNode.Kind ==
RegexNodeKind
.Concatenate ? endingNode.Child(0) : endingNode;
1300
var newAlternate = new RegexNode(
RegexNodeKind
.Alternate, alternation.Options);
1303
if (children[i].Kind ==
RegexNodeKind
.Concatenate)
1311
newAlternate.AddChild(new RegexNode(
RegexNodeKind
.Empty, children[i].Options));
1316
if (alternation.Parent is RegexNode { Kind:
RegexNodeKind
.Atomic })
1318
var atomic = new RegexNode(
RegexNodeKind
.Atomic, alternation.Options);
1325
var newConcat = new RegexNode(
RegexNodeKind
.Concatenate, alternation.Options);
1341
Debug.Assert(node.Kind ==
RegexNodeKind
.Alternate);
1352
case
RegexNodeKind
.Empty when !seenEmpty:
1356
case
RegexNodeKind
.Empty:
1357
case
RegexNodeKind
.Nothing:
1384
Debug.Assert(alternation.Kind ==
RegexNodeKind
.Alternate);
1414
if (startingNode.Kind ==
RegexNodeKind
.One)
1434
if (startingNode.Kind ==
RegexNodeKind
.One)
1448
Debug.Assert(startingNode.Kind ==
RegexNodeKind
.Multi);
1477
new RegexNode(
RegexNodeKind
.One, startingNodeOptions, startingSpan[0]) :
1478
new RegexNode(
RegexNodeKind
.Multi, startingNodeOptions, startingSpan.ToString());
1479
var newAlternate = new RegexNode(
RegexNodeKind
.Alternate, startingNodeOptions);
1483
ProcessOneOrMulti(branch.Kind ==
RegexNodeKind
.Concatenate ? branch.Child(0) : branch, startingSpan);
1491
if (node.Kind ==
RegexNodeKind
.One)
1495
node.Kind =
RegexNodeKind
.Empty;
1500
Debug.Assert(node.Kind ==
RegexNodeKind
.Multi);
1504
node.Kind =
RegexNodeKind
.Empty;
1509
node.Kind =
RegexNodeKind
.One;
1521
if (alternation.Parent is RegexNode parent && parent.Kind ==
RegexNodeKind
.Atomic)
1523
var atomic = new RegexNode(
RegexNodeKind
.Atomic, startingNodeOptions);
1528
var newConcat = new RegexNode(
RegexNodeKind
.Concatenate, startingNodeOptions);
1548
RegexNode branch = Kind ==
RegexNodeKind
.Concatenate ? Child(0) : this;
1549
return branch.Kind is
RegexNodeKind
.One or
RegexNodeKind
.Multi ? branch : null;
1555
Debug.Assert(Kind is
RegexNodeKind
.One or
RegexNodeKind
.Multi || (IsOneFamily && M > 0));
1570
Debug.Assert(Kind is
RegexNodeKind
.Alternate);
1594
if (startingLiteralNode.IsOneFamily || startingLiteralNode.Kind is
RegexNodeKind
.Multi)
1640
case
RegexNodeKind
.One:
1641
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy when node.M > 0:
1642
case
RegexNodeKind
.Notone:
1643
case
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy when node.M > 0:
1644
case
RegexNodeKind
.Set:
1645
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy when node.M > 0:
1646
case
RegexNodeKind
.Multi:
1649
case
RegexNodeKind
.Atomic:
1650
case
RegexNodeKind
.Concatenate:
1651
case
RegexNodeKind
.Capture:
1652
case
RegexNodeKind
.Group:
1653
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M > 0:
1654
case
RegexNodeKind
.PositiveLookaround when allowZeroWidth:
1675
case
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy:
1678
case
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy:
1681
case
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy:
1697
case
RegexNodeKind
.Multi:
1740
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1746
return new RegexNode(
RegexNodeKind
.Empty, Options);
1756
if (child.Kind ==
RegexNodeKind
.Nothing)
1782
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1799
if (at.Kind ==
RegexNodeKind
.Concatenate &&
1818
else if (at.Kind is
RegexNodeKind
.Multi or
RegexNodeKind
.One)
1832
if (prev.Kind ==
RegexNodeKind
.One)
1834
prev.Kind =
RegexNodeKind
.Multi;
1839
((at.Kind ==
RegexNodeKind
.One) ? $"{prev.Str}{at.Ch}" : prev.Str + at.Str) :
1840
((at.Kind ==
RegexNodeKind
.One) ? $"{at.Ch}{prev.Str}" : at.Str + prev.Str);
1842
else if (at.Kind ==
RegexNodeKind
.Empty)
1865
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1903
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy when nextNode.Kind == currentNode.Kind && currentNode.Ch == nextNode.Ch:
1904
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy when nextNode.Kind == currentNode.Kind && currentNode.Str == nextNode.Str:
1906
currentNode.Kind is
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloopatomic)
1929
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy when nextNode.Kind ==
RegexNodeKind
.One && currentNode.Ch == nextNode.Ch:
1930
case
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notonelazy when nextNode.Kind ==
RegexNodeKind
.Notone && currentNode.Ch == nextNode.Ch:
1931
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy when nextNode.Kind ==
RegexNodeKind
.Set && currentNode.Str == nextNode.Str:
1945
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy when
1946
nextNode.Kind ==
RegexNodeKind
.Multi &&
1979
nextNode.Kind =
RegexNodeKind
.One;
1997
case
RegexNodeKind
.One when (nextNode.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy) && currentNode.Ch == nextNode.Ch:
1998
case
RegexNodeKind
.Notone when (nextNode.Kind is
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy) && currentNode.Ch == nextNode.Ch:
1999
case
RegexNodeKind
.Set when (nextNode.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy) && currentNode.Str == nextNode.Str:
2012
case
RegexNodeKind
.Notone when nextNode.Kind == currentNode.Kind && currentNode.Ch == nextNode.Ch:
2013
case
RegexNodeKind
.Set when nextNode.Kind ==
RegexNodeKind
.Set && currentNode.Str == nextNode.Str:
2014
currentNode.MakeRep(
RegexNodeKind
.Oneloop, 2, 2);
2019
case
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
2020
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
2021
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
2022
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary or
2023
RegexNodeKind
.ECMABoundary or
RegexNodeKind
.NonECMABoundary
2067
if (Kind is not
RegexNodeKind
.Concatenate)
2091
while (node.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
2099
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: true, allowLazy: false):
2108
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: false, allowLazy: true):
2124
node.Kind -=
RegexNodeKind
.Onelazy -
RegexNodeKind
.Oneloop; // lazy to greedy
2128
case
RegexNodeKind
.Loop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: true, allowLazy: false):
2129
case
RegexNodeKind
.Lazyloop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: false, allowLazy: true):
2143
while (loopChild.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
2155
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
2156
RegexNodeKind
.Multi or
2157
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set &&
2162
else if (node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop)
2166
goto case
RegexNodeKind
.Loop;
2174
case
RegexNodeKind
.Loop:
2184
case
RegexNodeKind
.Lazyloop:
2194
case
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional:
2205
for (int b = node.Kind ==
RegexNodeKind
.ExpressionConditional ? 1 : 0; b < alternateBranches; b++)
2219
Debug.Assert(Kind is
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround);
2227
if (Kind is
RegexNodeKind
.NegativeLookaround && ContainsKind(Child(0), [
RegexNodeKind
.Backreference,
RegexNodeKind
.BackreferenceConditional]) is false)
2242
if (node is { Kind:
RegexNodeKind
.Capture, N: -1 })
2273
if (Kind is
RegexNodeKind
.PositiveLookaround)
2276
child.Kind is
RegexNodeKind
.Empty)
2281
else if (Kind is
RegexNodeKind
.NegativeLookaround)
2286
if (child.Kind is
RegexNodeKind
.Empty)
2288
Kind =
RegexNodeKind
.Nothing;
2296
private static bool IsZeroWidthAssertion(
RegexNodeKind
kind) => kind is
2297
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround or
2298
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
2299
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
2300
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
2301
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
2302
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary or
2303
RegexNodeKind
.UpdateBumpalong;
2307
private static bool? ContainsKind(RegexNode node, ReadOnlySpan<
RegexNodeKind
> kinds)
2309
foreach (
RegexNodeKind
kind in kinds)
2339
Debug.Assert(Kind ==
RegexNodeKind
.BackreferenceConditional);
2348
AddChild(new RegexNode(
RegexNodeKind
.Empty, Options));
2357
Debug.Assert(Kind ==
RegexNodeKind
.ExpressionConditional);
2366
AddChild(new RegexNode(
RegexNodeKind
.Empty, Options));
2375
if (condition.Kind ==
RegexNodeKind
.PositiveLookaround && (condition.Options & RegexOptions.RightToLeft) == 0)
2400
Debug.Assert(loopNode.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop);
2411
case
RegexNodeKind
.One when CharInLoopSet(loopNode, literal.Ch): // e.g. \w+a\s : 'a' is in \w, check \s is disjoint
2412
case
RegexNodeKind
.Set when loopNode.Kind is
RegexNodeKind
.Setloop && RegexCharClass.IsSubsetOf(literal.Str!, loopNode.Str!): // e.g. \d+[0-9]\s
2424
case
RegexNodeKind
.Multi when CharInLoopSet(loopNode, literal.Str![0]) && !CharInLoopSet(loopNode, literal.Str[1]):
2436
RegexNodeKind
.Oneloop => loopNode.Ch == ch,
2437
RegexNodeKind
.Notoneloop => loopNode.Ch != ch,
2438
RegexNodeKind
.Setloop => RegexCharClass.CharInClass(ch, loopNode.Str!),
2460
while (node.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
2478
case
RegexNodeKind
.Concatenate:
2479
case
RegexNodeKind
.Capture:
2480
case
RegexNodeKind
.Atomic:
2484
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when subsequent.M > 0:
2492
case
RegexNodeKind
.PositiveLookaround when (subsequent.Options & RegexOptions.RightToLeft) == 0:
2516
case
RegexNodeKind
.Alternate:
2517
case
RegexNodeKind
.ExpressionConditional when childCount is 3: // condition, yes, and no branch
2532
case
RegexNodeKind
.Oneloop:
2533
case
RegexNodeKind
.Onelazy when allowLazy:
2536
case
RegexNodeKind
.One when node.Ch != subsequent.Ch:
2537
case
RegexNodeKind
.Notone when node.Ch == subsequent.Ch:
2538
case
RegexNodeKind
.Set when !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2539
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && node.Ch != subsequent.Ch:
2540
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch:
2541
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2542
case
RegexNodeKind
.Multi when node.Ch != subsequent.Str![0]:
2543
case
RegexNodeKind
.End:
2544
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when node.Ch != '\n':
2545
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsBoundaryWordChar(node.Ch):
2546
case
RegexNodeKind
.NonBoundary when node.M > 0 && !RegexCharClass.IsBoundaryWordChar(node.Ch):
2547
case
RegexNodeKind
.ECMABoundary when node.M > 0 && RegexCharClass.IsECMAWordChar(node.Ch):
2548
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && !RegexCharClass.IsECMAWordChar(node.Ch):
2551
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && node.Ch != subsequent.Ch:
2552
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch:
2553
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2562
case
RegexNodeKind
.Notoneloop:
2563
case
RegexNodeKind
.Notonelazy when allowLazy:
2566
case
RegexNodeKind
.One when node.Ch == subsequent.Ch:
2567
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch:
2568
case
RegexNodeKind
.Multi when node.Ch == subsequent.Str![0]:
2569
case
RegexNodeKind
.End:
2572
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch:
2581
case
RegexNodeKind
.Setloop:
2582
case
RegexNodeKind
.Setlazy when allowLazy:
2585
case
RegexNodeKind
.One when !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2586
case
RegexNodeKind
.Set when !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2587
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2588
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2589
case
RegexNodeKind
.Multi when !RegexCharClass.CharInClass(subsequent.Str![0], node.Str!):
2590
case
RegexNodeKind
.End:
2591
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when !RegexCharClass.CharInClass('\n', node.Str!):
2592
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsSubsetOf(node.Str!, RegexCharClass.WordClass):
2593
case
RegexNodeKind
.NonBoundary when node.M > 0 && node.Str is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass:
2594
case
RegexNodeKind
.ECMABoundary when node.M > 0 && node.Str is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass:
2595
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && node.Str is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass:
2598
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2599
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2608
case
RegexNodeKind
.Loop:
2609
case
RegexNodeKind
.Lazyloop when allowLazy:
2632
case
RegexNodeKind
.One when !CharInStartingOrEndingSet(subsequent.Ch):
2633
case
RegexNodeKind
.Set when !MayOverlapStartingOrEndingSet(subsequent.Str!):
2634
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && !CharInStartingOrEndingSet(subsequent.Ch):
2635
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !MayOverlapStartingOrEndingSet(subsequent.Str!):
2636
case
RegexNodeKind
.Multi when !CharInStartingOrEndingSet(subsequent.Str![0]):
2637
case
RegexNodeKind
.End:
2638
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when !CharInStartingOrEndingSet('\n'):
2639
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsSubsetOf(loopStartingSet, RegexCharClass.WordClass) && RegexCharClass.IsSubsetOf(loopEndingSet, RegexCharClass.WordClass):
2640
case
RegexNodeKind
.NonBoundary when node.M > 0 && (loopStartingSet is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass) && (loopEndingSet is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass):
2641
case
RegexNodeKind
.ECMABoundary when node.M > 0 && (loopStartingSet is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass) && (loopEndingSet is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass):
2642
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && (loopStartingSet is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass) && (loopEndingSet is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass):
2645
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && !CharInStartingOrEndingSet(subsequent.Ch):
2646
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !MayOverlapStartingOrEndingSet(subsequent.Str!):
2701
case
RegexNodeKind
.Atomic:
2702
case
RegexNodeKind
.Alternate:
2703
case
RegexNodeKind
.Capture:
2707
case
RegexNodeKind
.Concatenate:
2738
RegexNodeKind
.Alternate => true,
2739
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when M != N => true,
2740
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy or
2741
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notonelazy or
2742
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy when M != N => true,
2786
Debug.Assert(node.Kind is not
RegexNodeKind
.Concatenate, "The existing logic assumes that the node itself isn't a concatenation.");
2799
case
RegexNodeKind
.Atomic:
2800
case
RegexNodeKind
.Alternate:
2801
case
RegexNodeKind
.Capture:
2805
case
RegexNodeKind
.Concatenate:
2841
case
RegexNodeKind
.One:
2842
case
RegexNodeKind
.Notone:
2843
case
RegexNodeKind
.Set:
2847
case
RegexNodeKind
.Multi:
2851
case
RegexNodeKind
.Notonelazy:
2852
case
RegexNodeKind
.Notoneloop:
2853
case
RegexNodeKind
.Notoneloopatomic:
2854
case
RegexNodeKind
.Onelazy:
2855
case
RegexNodeKind
.Oneloop:
2856
case
RegexNodeKind
.Oneloopatomic:
2857
case
RegexNodeKind
.Setlazy:
2858
case
RegexNodeKind
.Setloop:
2859
case
RegexNodeKind
.Setloopatomic:
2863
case
RegexNodeKind
.Lazyloop:
2864
case
RegexNodeKind
.Loop:
2868
case
RegexNodeKind
.Alternate:
2881
case
RegexNodeKind
.BackreferenceConditional:
2885
case
RegexNodeKind
.ExpressionConditional:
2889
case
RegexNodeKind
.Concatenate:
2901
case
RegexNodeKind
.Atomic:
2902
case
RegexNodeKind
.Capture:
2903
case
RegexNodeKind
.Group:
2908
case
RegexNodeKind
.Empty:
2909
case
RegexNodeKind
.Nothing:
2910
case
RegexNodeKind
.UpdateBumpalong:
2914
case
RegexNodeKind
.Beginning:
2915
case
RegexNodeKind
.Bol:
2916
case
RegexNodeKind
.Boundary:
2917
case
RegexNodeKind
.ECMABoundary:
2918
case
RegexNodeKind
.End:
2919
case
RegexNodeKind
.EndZ:
2920
case
RegexNodeKind
.Eol:
2921
case
RegexNodeKind
.NonBoundary:
2922
case
RegexNodeKind
.NonECMABoundary:
2923
case
RegexNodeKind
.Start:
2924
case
RegexNodeKind
.NegativeLookaround:
2925
case
RegexNodeKind
.PositiveLookaround:
2927
case
RegexNodeKind
.Backreference:
2935
goto case
RegexNodeKind
.Empty;
2954
case
RegexNodeKind
.One:
2955
case
RegexNodeKind
.Notone:
2956
case
RegexNodeKind
.Set:
2960
case
RegexNodeKind
.Multi:
2964
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
2965
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
2966
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic:
2970
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop:
2985
case
RegexNodeKind
.Alternate:
3008
case
RegexNodeKind
.BackreferenceConditional:
3009
case
RegexNodeKind
.ExpressionConditional:
3012
int i = Kind ==
RegexNodeKind
.BackreferenceConditional ? 0 : 1;
3018
case
RegexNodeKind
.Concatenate:
3040
case
RegexNodeKind
.Atomic:
3041
case
RegexNodeKind
.Capture:
3046
case
RegexNodeKind
.Empty:
3047
case
RegexNodeKind
.Nothing:
3048
case
RegexNodeKind
.UpdateBumpalong:
3049
case
RegexNodeKind
.Beginning:
3050
case
RegexNodeKind
.Bol:
3051
case
RegexNodeKind
.Boundary:
3052
case
RegexNodeKind
.ECMABoundary:
3053
case
RegexNodeKind
.End:
3054
case
RegexNodeKind
.EndZ:
3055
case
RegexNodeKind
.Eol:
3056
case
RegexNodeKind
.NonBoundary:
3057
case
RegexNodeKind
.NonECMABoundary:
3058
case
RegexNodeKind
.Start:
3059
case
RegexNodeKind
.PositiveLookaround:
3060
case
RegexNodeKind
.NegativeLookaround:
3064
case
RegexNodeKind
.Backreference:
3072
goto case
RegexNodeKind
.Empty;
3103
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate, $"Expected Concatenate, got {Kind}");
3125
while (child.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Atomic)
3131
if (child.Kind is
RegexNodeKind
.One)
3144
else if (child.Kind is
RegexNodeKind
.Multi)
3156
else if (child.Kind is
RegexNodeKind
.Set ||
3157
(child.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic && child.M == child.N))
3166
vsb.Append((char)(twoChars[0] | 0x20), child.Kind is
RegexNodeKind
.Set ? 1 : child.M);
3168
else if (child.Kind is
RegexNodeKind
.Concatenate)
3188
else if (child.Kind is
RegexNodeKind
.Empty)
3239
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate, $"Expected Concatenate, got {Kind}");
3243
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set => true,
3244
RegexNodeKind
.Multi => true,
3245
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloopatomic or
3246
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloopatomic or
3247
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic
3289
return new RegexNode(
RegexNodeKind
.Empty, Options);
3295
case <= MultiVsRepeaterLimit when Kind ==
RegexNodeKind
.One:
3301
Kind =
RegexNodeKind
.Multi;
3310
case
RegexNodeKind
.One:
3311
case
RegexNodeKind
.Notone:
3312
case
RegexNodeKind
.Set:
3313
MakeRep(lazy ?
RegexNodeKind
.Onelazy :
RegexNodeKind
.Oneloop, min, max);
3317
var result = new RegexNode(lazy ?
RegexNodeKind
.Lazyloop :
RegexNodeKind
.Loop, Options, min, max);
3448
public bool IsSetFamily => Kind is
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy;
3451
public bool IsOneFamily => Kind is
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy;
3454
public bool IsNotoneFamily => Kind is
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy;
parent\src\System\Text\RegularExpressions\RegexParser.cs (87)
277
StartGroup(new RegexNode(
RegexNodeKind
.Capture, (_options & ~RegexOptions.IgnoreCase), 0, -1));
347
_unit = new RegexNode(
RegexNodeKind
.Set, _options & ~RegexOptions.IgnoreCase, setString);
400
_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ?
RegexNodeKind
.Bol :
RegexNodeKind
.Beginning, _options);
411
_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ?
RegexNodeKind
.Eol :
RegexNodeKind
.EndZ, _options);
418
_unit = new RegexNode(
RegexNodeKind
.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.AnyClass);
422
_unit = new RegexNode(
RegexNodeKind
.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.NotAnyNewLineClass);
426
_unit = new RegexNode(
RegexNodeKind
.Notone, _options & ~RegexOptions.IgnoreCase, '\n');
544
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
829
return new RegexNode(
RegexNodeKind
.Group, _options);
833
return new RegexNode(
RegexNodeKind
.Capture, _options, _autocap++, -1);
846
RegexNodeKind
nodeType;
853
nodeType =
RegexNodeKind
.Group;
859
nodeType =
RegexNodeKind
.PositiveLookaround;
865
nodeType =
RegexNodeKind
.NegativeLookaround;
870
nodeType =
RegexNodeKind
.Atomic;
893
nodeType =
RegexNodeKind
.PositiveLookaround;
904
nodeType =
RegexNodeKind
.NegativeLookaround;
1007
return new RegexNode(
RegexNodeKind
.Capture, _options, capnum, uncapnum);
1029
return new RegexNode(
RegexNodeKind
.BackreferenceConditional, _options, capnum);
1043
return new RegexNode(
RegexNodeKind
.BackreferenceConditional, _options, tmpCapnum);
1048
nodeType =
RegexNodeKind
.ExpressionConditional;
1072
nodeType =
RegexNodeKind
.Group;
1075
if (_group!.Kind !=
RegexNodeKind
.ExpressionConditional || _group.ChildCount() > 0)
1166
(_options & RegexOptions.AnyNewLine) != 0 ? AnyNewLineEndZNode() : new RegexNode(
RegexNodeKind
.EndZ, _options);
1171
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMAWordClass : RegexCharClass.WordClass);
1176
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMAWordClass : RegexCharClass.NotWordClass);
1181
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMASpaceClass : RegexCharClass.SpaceClass);
1186
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMASpaceClass : RegexCharClass.NotSpaceClass);
1191
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMADigitClass : RegexCharClass.DigitClass);
1196
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMADigitClass : RegexCharClass.NotDigitClass);
1213
return new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), cc.ToStringClass());
1217
if (result != null && result.Kind ==
RegexNodeKind
.Backreference && (result.Options & RegexOptions.IgnoreCase) != 0)
1278
IsCaptureSlot(capnum) ? new RegexNode(
RegexNodeKind
.Backreference, _options, capnum) :
1310
return scanOnly ? null : new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1324
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1344
_capnames?[capname] is int tmpCapnum ? new RegexNode(
RegexNodeKind
.Backreference, _options, tmpCapnum) :
1420
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1430
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1442
return new RegexNode(
RegexNodeKind
.Backreference, _options, tmpCapnum);
1480
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1741
var lookbehindCr = new RegexNode(
RegexNodeKind
.PositiveLookaround, lookbehindOpts);
1742
lookbehindCr.AddChild(new RegexNode(
RegexNodeKind
.One, lookbehindOptsNoCase, '\r'));
1745
var crThenLf = new RegexNode(
RegexNodeKind
.Concatenate, lookaheadOpts);
1747
crThenLf.AddChild(new RegexNode(
RegexNodeKind
.One, lookaheadOptsNoCase, '\n'));
1750
var guard = new RegexNode(
RegexNodeKind
.NegativeLookaround, lookaheadOpts);
1769
var crlfEnd = new RegexNode(
RegexNodeKind
.Concatenate, lookaheadOpts);
1770
crlfEnd.AddChild(new RegexNode(
RegexNodeKind
.One, lookaheadOptsNoCase, '\r'));
1771
crlfEnd.AddChild(new RegexNode(
RegexNodeKind
.One, lookaheadOptsNoCase, '\n'));
1772
crlfEnd.AddChild(new RegexNode(
RegexNodeKind
.End, lookaheadOpts));
1775
var anyNewLineOptEnd = new RegexNode(
RegexNodeKind
.Concatenate, lookaheadOpts);
1776
anyNewLineOptEnd.AddChild(new RegexNode(
RegexNodeKind
.Set, lookaheadOptsNoCase, RegexCharClass.AnyNewLineClass).MakeQuantifier(false, 0, 1));
1777
anyNewLineOptEnd.AddChild(new RegexNode(
RegexNodeKind
.End, lookaheadOpts));
1780
var innerAlt = new RegexNode(
RegexNodeKind
.Alternate, lookaheadOpts);
1783
var lookahead = new RegexNode(
RegexNodeKind
.PositiveLookaround, lookaheadOpts);
1787
var result = new RegexNode(
RegexNodeKind
.Concatenate, opts);
1806
var innerAlt = new RegexNode(
RegexNodeKind
.Alternate, lookaheadOpts);
1807
innerAlt.AddChild(new RegexNode(
RegexNodeKind
.Set, lookaheadOptsNoCase, RegexCharClass.AnyNewLineClass));
1808
innerAlt.AddChild(new RegexNode(
RegexNodeKind
.End, lookaheadOpts));
1809
var lookahead = new RegexNode(
RegexNodeKind
.PositiveLookaround, lookaheadOpts);
1813
var result = new RegexNode(
RegexNodeKind
.Concatenate, opts);
1832
var innerAlt = new RegexNode(
RegexNodeKind
.Alternate, lookbehindOpts);
1833
innerAlt.AddChild(new RegexNode(
RegexNodeKind
.Set, lookbehindOptsNoCase, RegexCharClass.AnyNewLineClass));
1834
innerAlt.AddChild(new RegexNode(
RegexNodeKind
.Beginning, lookbehindOpts));
1835
var lookbehind = new RegexNode(
RegexNodeKind
.PositiveLookaround, lookbehindOpts);
1839
var result = new RegexNode(
RegexNodeKind
.Concatenate, opts);
1847
private readonly
RegexNodeKind
TypeFromCode(char ch) =>
1850
'b' => (_options & RegexOptions.ECMAScript) != 0 ?
RegexNodeKind
.ECMABoundary :
RegexNodeKind
.Boundary,
1851
'B' => (_options & RegexOptions.ECMAScript) != 0 ?
RegexNodeKind
.NonECMABoundary :
RegexNodeKind
.NonBoundary,
1852
'A' =>
RegexNodeKind
.Beginning,
1853
'G' =>
RegexNodeKind
.Start,
1854
'Z' =>
RegexNodeKind
.EndZ,
1855
'z' =>
RegexNodeKind
.End,
1856
_ =>
RegexNodeKind
.Nothing,
2198
_concatenation!.AddChild(new RegexNode(
RegexNodeKind
.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch)));
2228
if (_group.Kind ==
RegexNodeKind
.ExpressionConditional && _group.ChildCount() == 0)
2244
_alternation = new RegexNode(
RegexNodeKind
.Alternate, _options);
2245
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
2253
if (_group!.Kind is
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.BackreferenceConditional)
2262
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
2268
if (_group!.Kind is
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.BackreferenceConditional)
2272
if (_group.Kind ==
RegexNodeKind
.BackreferenceConditional && _group.ChildCount() > 2 || _group.ChildCount() > 3)
parent\src\System\Text\RegularExpressions\RegexPrefixAnalyzer.cs (224)
84
case
RegexNodeKind
.Atomic:
85
case
RegexNodeKind
.Capture:
90
case
RegexNodeKind
.Bol:
91
case
RegexNodeKind
.Eol:
92
case
RegexNodeKind
.Boundary:
93
case
RegexNodeKind
.ECMABoundary:
94
case
RegexNodeKind
.NonBoundary:
95
case
RegexNodeKind
.NonECMABoundary:
96
case
RegexNodeKind
.Beginning:
97
case
RegexNodeKind
.Start:
98
case
RegexNodeKind
.EndZ:
99
case
RegexNodeKind
.End:
100
case
RegexNodeKind
.Empty:
101
case
RegexNodeKind
.UpdateBumpalong:
102
case
RegexNodeKind
.PositiveLookaround:
103
case
RegexNodeKind
.NegativeLookaround:
112
case
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloopatomic when !ignoreCase || !RegexCharClass.ParticipatesInCaseConversion(node.Ch):
114
int reps = node.Kind is
RegexNodeKind
.One ? 1 : Math.Min(node.M, MaxPrefixLength);
119
return node.Kind is
RegexNodeKind
.One || reps == node.N;
124
case
RegexNodeKind
.Multi:
156
case
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic when !RegexCharClass.IsNegated(node.Str!): // negated sets are too complex to analyze
164
int reps = node.Kind is
RegexNodeKind
.Set ? 1 : Math.Min(node.M, MaxPrefixLength);
209
return node.Kind is
RegexNodeKind
.Set || reps == node.N;
212
case
RegexNodeKind
.Concatenate:
226
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M > 0:
242
case
RegexNodeKind
.Alternate:
363
case
RegexNodeKind
.Concatenate:
377
case
RegexNodeKind
.Alternate when !rtl: // for RTL we'd need to be matching the suffixes of the alternation cases
422
case
RegexNodeKind
.One:
427
case
RegexNodeKind
.Multi:
432
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy when node.M > 0:
439
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M > 0:
454
case
RegexNodeKind
.Atomic:
455
case
RegexNodeKind
.Capture:
459
case
RegexNodeKind
.Bol:
460
case
RegexNodeKind
.Eol:
461
case
RegexNodeKind
.Boundary:
462
case
RegexNodeKind
.ECMABoundary:
463
case
RegexNodeKind
.NonBoundary:
464
case
RegexNodeKind
.NonECMABoundary:
465
case
RegexNodeKind
.Beginning:
466
case
RegexNodeKind
.Start:
467
case
RegexNodeKind
.EndZ:
468
case
RegexNodeKind
.End:
469
case
RegexNodeKind
.Empty:
470
case
RegexNodeKind
.UpdateBumpalong:
471
case
RegexNodeKind
.PositiveLookaround:
472
case
RegexNodeKind
.NegativeLookaround:
491
case
RegexNodeKind
.Atomic:
492
case
RegexNodeKind
.Capture:
493
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M > 0:
497
case
RegexNodeKind
.Concatenate:
600
case
RegexNodeKind
.One:
609
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when node.M > 0:
621
case
RegexNodeKind
.Multi:
633
case
RegexNodeKind
.Set:
641
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when node.M > 0:
652
case
RegexNodeKind
.Notone:
658
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic when node.M == node.N:
662
case
RegexNodeKind
.Beginning:
663
case
RegexNodeKind
.Bol:
664
case
RegexNodeKind
.Boundary:
665
case
RegexNodeKind
.ECMABoundary:
666
case
RegexNodeKind
.Empty:
667
case
RegexNodeKind
.End:
668
case
RegexNodeKind
.EndZ:
669
case
RegexNodeKind
.Eol:
670
case
RegexNodeKind
.NonBoundary:
671
case
RegexNodeKind
.NonECMABoundary:
672
case
RegexNodeKind
.UpdateBumpalong:
673
case
RegexNodeKind
.Start:
674
case
RegexNodeKind
.NegativeLookaround:
675
case
RegexNodeKind
.PositiveLookaround:
681
case
RegexNodeKind
.Atomic:
682
case
RegexNodeKind
.Group:
683
case
RegexNodeKind
.Capture:
686
case
RegexNodeKind
.Lazyloop or
RegexNodeKind
.Loop when node.M > 0:
696
case
RegexNodeKind
.Concatenate:
709
case
RegexNodeKind
.Alternate when thorough:
954
case
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloopatomic:
959
return node.Kind is
RegexNodeKind
.One || node.M > 0 ? true : null;
963
case
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy:
977
return node.Kind is
RegexNodeKind
.Notone || node.M > 0 ? true : null;
981
case
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic:
996
node.Kind is
RegexNodeKind
.Set || node.M > 0 ? true :
1000
case
RegexNodeKind
.Multi:
1012
case
RegexNodeKind
.Empty:
1013
case
RegexNodeKind
.Nothing:
1014
case
RegexNodeKind
.Bol:
1015
case
RegexNodeKind
.Eol:
1016
case
RegexNodeKind
.Boundary:
1017
case
RegexNodeKind
.NonBoundary:
1018
case
RegexNodeKind
.ECMABoundary:
1019
case
RegexNodeKind
.NonECMABoundary:
1020
case
RegexNodeKind
.Beginning:
1021
case
RegexNodeKind
.Start:
1022
case
RegexNodeKind
.EndZ:
1023
case
RegexNodeKind
.End:
1024
case
RegexNodeKind
.UpdateBumpalong:
1025
case
RegexNodeKind
.PositiveLookaround:
1026
case
RegexNodeKind
.NegativeLookaround:
1030
case
RegexNodeKind
.Atomic:
1031
case
RegexNodeKind
.Capture:
1037
case
RegexNodeKind
.Loop:
1038
case
RegexNodeKind
.Lazyloop:
1050
case
RegexNodeKind
.Concatenate:
1081
case
RegexNodeKind
.Alternate:
1102
case
RegexNodeKind
.BackreferenceConditional:
1103
case
RegexNodeKind
.ExpressionConditional:
1104
int branchStart = node.Kind is
RegexNodeKind
.BackreferenceConditional ? 0 : 1;
1113
case
RegexNodeKind
.Backreference:
1138
while (node.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.Capture)
1142
if (node.Kind !=
RegexNodeKind
.Concatenate)
1155
while (firstChild.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.Capture)
1159
if (firstChild.Kind is not (
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy) || firstChild.N != int.MaxValue)
1167
if (nextChild.Kind ==
RegexNodeKind
.UpdateBumpalong)
1224
while ((nextChild.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate) ||
1225
(nextChild.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop && nextChild.M >= 1))
1233
(nextChild.Kind is
RegexNodeKind
.Set || nextChild.M >= 1))
1279
case
RegexNodeKind
.PositiveLookaround:
1284
case
RegexNodeKind
.Bol:
1285
case
RegexNodeKind
.Eol:
1286
case
RegexNodeKind
.Beginning:
1287
case
RegexNodeKind
.Start:
1288
case
RegexNodeKind
.EndZ:
1289
case
RegexNodeKind
.End:
1290
case
RegexNodeKind
.Boundary:
1291
case
RegexNodeKind
.ECMABoundary:
1292
case
RegexNodeKind
.NegativeLookaround:
1293
case
RegexNodeKind
.Empty:
1297
case
RegexNodeKind
.Atomic:
1298
case
RegexNodeKind
.Capture:
1303
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M >= 1:
1309
case
RegexNodeKind
.Concatenate:
1330
public static
RegexNodeKind
FindLeadingAnchor(RegexNode node) =>
1334
public static
RegexNodeKind
FindTrailingAnchor(RegexNode node) =>
1338
private static
RegexNodeKind
FindLeadingOrTrailingAnchor(RegexNode node, bool leading)
1344
return
RegexNodeKind
.Unknown;
1351
case
RegexNodeKind
.Bol:
1352
case
RegexNodeKind
.Eol:
1353
case
RegexNodeKind
.Beginning:
1354
case
RegexNodeKind
.Start:
1355
case
RegexNodeKind
.EndZ:
1356
case
RegexNodeKind
.End:
1360
case
RegexNodeKind
.Atomic:
1361
case
RegexNodeKind
.Capture:
1362
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when leading && node.M >= 1:
1363
case
RegexNodeKind
.PositiveLookaround when leading && (node.Options & RegexOptions.RightToLeft) == 0:
1373
case
RegexNodeKind
.Concatenate:
1380
RegexNodeKind
bestAnchorFound =
RegexNodeKind
.Unknown;
1388
case
RegexNodeKind
.Empty or
RegexNodeKind
.NegativeLookaround:
1389
case
RegexNodeKind
.PositiveLookaround when ((node.Options | tmpChild.Options) & RegexOptions.RightToLeft) != 0:
1390
case
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary:
1394
case
RegexNodeKind
.PositiveLookaround:
1416
if (node.Child(i).Kind is not (
RegexNodeKind
.Empty or
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround))
1424
if (bestAnchorFound is not
RegexNodeKind
.Unknown)
1446
static
RegexNodeKind
ChooseBetterAnchor(
RegexNodeKind
anchor1,
RegexNodeKind
anchor2)
1449
anchor1 ==
RegexNodeKind
.Unknown ? anchor2 :
1450
anchor2 ==
RegexNodeKind
.Unknown ? anchor1 :
1454
static int RankAnchorQuality(
RegexNodeKind
node) =>
1457
RegexNodeKind
.Beginning => 3,
1458
RegexNodeKind
.Start => 3,
1459
RegexNodeKind
.End => 3,
1460
RegexNodeKind
.EndZ => 3,
1462
RegexNodeKind
.Bol => 2,
1463
RegexNodeKind
.Eol => 2,
1465
RegexNodeKind
.Boundary => 1,
1466
RegexNodeKind
.ECMABoundary => 1,
1472
static bool IsBestAnchor(
RegexNodeKind
anchor) =>
1474
anchor is
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
RegexNodeKind
.End or
RegexNodeKind
.EndZ;
1477
case
RegexNodeKind
.Alternate:
1481
RegexNodeKind
anchor = FindLeadingOrTrailingAnchor(node.Child(0), leading);
1482
if (anchor ==
RegexNodeKind
.Unknown)
1484
return
RegexNodeKind
.Unknown;
1494
return
RegexNodeKind
.Unknown;
1504
return
RegexNodeKind
.Unknown;
parent\src\System\Text\RegularExpressions\RegexTreeAnalyzer.cs (16)
59
case
RegexNodeKind
.Atomic:
60
case
RegexNodeKind
.NegativeLookaround:
61
case
RegexNodeKind
.PositiveLookaround:
66
case
RegexNodeKind
.Capture:
71
case
RegexNodeKind
.Loop:
72
case
RegexNodeKind
.Lazyloop:
90
RegexNodeKind
.Atomic or
RegexNodeKind
.NegativeLookaround or
RegexNodeKind
.PositiveLookaround => true,
94
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional => true,
97
RegexNodeKind
.Capture => true,
101
RegexNodeKind
.Concatenate => i == childCount - 1,
107
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.N == 1 => true,
RegexGenerator.cs (1)
373
if (node.Kind is
RegexNodeKind
.Backreference && (node.Options & RegexOptions.IgnoreCase) != 0)
RegexGenerator.Emitter.cs (210)
760
if (root.Kind is
RegexNodeKind
.Empty)
769
else if (root.Kind is
RegexNodeKind
.Nothing)
775
else if (root.Kind is
RegexNodeKind
.Multi or
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set)
784
writer.WriteLine($"int end = base.runtextpos = start {(!rtl ? "+" : "-")} {(root.Kind ==
RegexNodeKind
.Multi ? root.Str!.Length : 1)};");
812
rm.Tree.FindOptimizations.LeadingAnchor !=
RegexNodeKind
.Unknown ||
813
rm.Tree.FindOptimizations.TrailingAnchor !=
RegexNodeKind
.Unknown;
960
if (RegexPrefixAnalyzer.FindTrailingAnchor(regexTree.Root) ==
RegexNodeKind
.End &&
1082
case
RegexNodeKind
.Bol:
1118
case
RegexNodeKind
.End when regexTree.FindOptimizations.MaxPossibleLength is int maxLength:
1127
case
RegexNodeKind
.EndZ when regexTree.FindOptimizations.MaxPossibleLength is int maxLength:
1503
Debug.Assert(target.LoopNode.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic);
1625
Debug.Assert(node.Kind ==
RegexNodeKind
.Capture, "Every generated tree should begin with a capture node");
1807
Debug.Assert(node.Kind is
RegexNodeKind
.Alternate, $"Unexpected type: {node.Kind}");
1909
case
RegexNodeKind
.One:
1910
case
RegexNodeKind
.Set:
1915
case
RegexNodeKind
.Multi:
1922
case
RegexNodeKind
.Concatenate when child.Child(0) == startingLiteralNode && (startingLiteralNode.Kind is
RegexNodeKind
.One or
RegexNodeKind
.Set or
RegexNodeKind
.Multi):
1932
child.Child(0).Kind is
RegexNodeKind
.Multi ?
1934
new RegexNode(
RegexNodeKind
.Empty, child.Options)); // single, so removing it yields empty
1978
Debug.Assert(multi.Kind is
RegexNodeKind
.Multi, $"Expected a Multi node, got {multi.Kind}");
1980
new(
RegexNodeKind
.One, multi.Options, multi.Str[1]) :
1981
new(
RegexNodeKind
.Multi, multi.Options, multi.Str.Substring(1));
2205
Debug.Assert(node.Kind is
RegexNodeKind
.Backreference, $"Unexpected type: {node.Kind}");
2274
Debug.Assert(node.Kind is
RegexNodeKind
.BackreferenceConditional, $"Unexpected type: {node.Kind}");
2287
RegexNode? noBranch = node.Child(1) is { Kind: not
RegexNodeKind
.Empty } childNo ? childNo : null;
2447
Debug.Assert(node.Kind is
RegexNodeKind
.ExpressionConditional, $"Unexpected type: {node.Kind}");
2463
RegexNode? noBranch = node.Child(2) is { Kind: not
RegexNodeKind
.Empty } childNo ? childNo : null;
2627
Debug.Assert(node.Kind is
RegexNodeKind
.Capture, $"Unexpected type: {node.Kind}");
2720
Debug.Assert(node.Kind is
RegexNodeKind
.PositiveLookaround, $"Unexpected type: {node.Kind}");
2761
Debug.Assert(node.Kind is
RegexNodeKind
.NegativeLookaround, $"Unexpected type: {node.Kind}");
2894
case
RegexNodeKind
.Empty:
2898
case
RegexNodeKind
.Nothing:
2903
case
RegexNodeKind
.Atomic when !rm.Analysis.MayBacktrack(node.Child(0)):
2909
case
RegexNodeKind
.Concatenate:
2921
case
RegexNodeKind
.Beginning:
2922
case
RegexNodeKind
.Start:
2923
case
RegexNodeKind
.Bol:
2924
case
RegexNodeKind
.Eol:
2925
case
RegexNodeKind
.End:
2926
case
RegexNodeKind
.EndZ:
2930
case
RegexNodeKind
.Boundary:
2931
case
RegexNodeKind
.NonBoundary:
2932
case
RegexNodeKind
.ECMABoundary:
2933
case
RegexNodeKind
.NonECMABoundary:
2937
case
RegexNodeKind
.One:
2938
case
RegexNodeKind
.Notone:
2939
case
RegexNodeKind
.Set:
2943
case
RegexNodeKind
.Multi when (node.Options & RegexOptions.RightToLeft) == 0:
2947
case
RegexNodeKind
.UpdateBumpalong:
2958
case
RegexNodeKind
.Multi:
2962
case
RegexNodeKind
.Oneloop:
2963
case
RegexNodeKind
.Notoneloop:
2964
case
RegexNodeKind
.Setloop:
2968
case
RegexNodeKind
.Onelazy:
2969
case
RegexNodeKind
.Notonelazy:
2970
case
RegexNodeKind
.Setlazy:
2974
case
RegexNodeKind
.Oneloopatomic:
2975
case
RegexNodeKind
.Notoneloopatomic:
2976
case
RegexNodeKind
.Setloopatomic:
2980
case
RegexNodeKind
.Loop:
2984
case
RegexNodeKind
.Lazyloop:
2988
case
RegexNodeKind
.Alternate:
2992
case
RegexNodeKind
.Backreference:
2996
case
RegexNodeKind
.BackreferenceConditional:
3000
case
RegexNodeKind
.ExpressionConditional:
3004
case
RegexNodeKind
.Atomic:
3009
case
RegexNodeKind
.Capture:
3013
case
RegexNodeKind
.PositiveLookaround:
3017
case
RegexNodeKind
.NegativeLookaround:
3030
Debug.Assert(node.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround or
RegexNodeKind
.ExpressionConditional, $"Unexpected type: {node.Kind}");
3031
Debug.Assert(node.Kind is
RegexNodeKind
.ExpressionConditional ? node.ChildCount() >= 1 : node.ChildCount() == 1, $"Unexpected number of children: {node.ChildCount()}");
3033
Debug.Assert(node.Kind is
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround or
RegexNodeKind
.ExpressionConditional || rm.Analysis.MayBacktrack(node.Child(0)), "Expected lookaround/conditional or a child that may backtrack");
3060
Debug.Assert(node.Kind is
RegexNodeKind
.UpdateBumpalong, $"Unexpected type: {node.Kind}");
3072
Debug.Assert(node.Kind is
RegexNodeKind
.Concatenate, $"Unexpected type: {node.Kind}");
3120
else if (child.Kind is
RegexNodeKind
.Multi)
3131
int repeatCount = child.Kind is
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set ? 1 : child.M;
3189
if (next.Kind is not
RegexNodeKind
.UpdateBumpalong) // skip node types that don't have a semantic impact
3246
Debug.Assert(node.Kind is
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary or
RegexNodeKind
.ECMABoundary or
RegexNodeKind
.NonECMABoundary, $"Unexpected kind: {node.Kind}");
3248
string negation = node.Kind is
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary ? "!" : "";
3253
case
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary:
3286
Debug.Assert(node.Kind is
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
RegexNodeKind
.Bol or
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol, $"Unexpected type: {node.Kind}");
3292
case
RegexNodeKind
.Beginning:
3293
case
RegexNodeKind
.Start:
3302
using (EmitBlock(writer, node.Kind ==
RegexNodeKind
.Beginning ?
3311
case
RegexNodeKind
.Bol:
3320
case
RegexNodeKind
.End:
3329
case
RegexNodeKind
.EndZ:
3338
case
RegexNodeKind
.Eol:
3352
Debug.Assert(node.Kind is
RegexNodeKind
.Multi, $"Unexpected type: {node.Kind}");
3401
Debug.Assert(node.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop, $"Unexpected type: {node.Kind}");
3500
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy =>
3502
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy =>
3504
RegexNodeKind
.Multi =>
3579
Debug.Assert(node.Kind is
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy, $"Unexpected type: {node.Kind}");
3680
node.Kind is
RegexNodeKind
.Notonelazy &&
3747
node.Kind is
RegexNodeKind
.Setlazy &&
3826
Debug.Assert(node.Kind is
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
4252
Debug.Assert(node.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic, $"Unexpected type: {node.Kind}");
4384
Debug.Assert(node.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic, $"Unexpected type: {node.Kind}");
4422
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
4442
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
5064
if (node.Kind ==
RegexNodeKind
.Multi)
5589
RegexNodeKind
.Alternate => $"Match with {node.ChildCount()} alternative expressions{(rm.Analysis.IsAtomicByAncestor(node) ? ", atomically" : "")}.",
5590
RegexNodeKind
.Atomic => $"Atomic group.",
5591
RegexNodeKind
.Beginning => "Match if at the beginning of the string.",
5592
RegexNodeKind
.Bol => "Match if at the beginning of a line.",
5593
RegexNodeKind
.Boundary => $"Match if at a word boundary.",
5594
RegexNodeKind
.Capture when node.M == -1 && node.N != -1 => $"Non-capturing balancing group. Uncaptures the {DescribeCapture(node.N, rm)}.",
5595
RegexNodeKind
.Capture when node.N != -1 => $"Balancing group. Captures the {DescribeCapture(node.M, rm)} and uncaptures the {DescribeCapture(node.N, rm)}.",
5596
RegexNodeKind
.Capture when node.N == -1 => $"{DescribeCapture(node.M, rm)}.",
5597
RegexNodeKind
.Concatenate => "Match a sequence of expressions.",
5598
RegexNodeKind
.ECMABoundary => $"Match if at a word boundary (according to ECMAScript rules).",
5599
RegexNodeKind
.Empty => $"Match an empty string.",
5600
RegexNodeKind
.End => "Match if at the end of the string.",
5601
RegexNodeKind
.EndZ => "Match if at the end of the string or if before an ending newline.",
5602
RegexNodeKind
.Eol => "Match if at the end of a line.",
5603
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop => node.M == 0 && node.N == 1 ? $"Optional ({(node.Kind is
RegexNodeKind
.Loop ? "greedy" : "lazy")})." : $"Loop {DescribeLoop(node, rm)}{direction}.",
5604
RegexNodeKind
.Multi => $"Match the string {Literal(node.Str!)}{direction}.",
5605
RegexNodeKind
.NonBoundary => $"Match if at anything other than a word boundary.",
5606
RegexNodeKind
.NonECMABoundary => $"Match if at anything other than a word boundary (according to ECMAScript rules).",
5607
RegexNodeKind
.Nothing => $"Fail to match.",
5608
RegexNodeKind
.Notone => $"Match any character other than {Literal(node.Ch)}{direction}.",
5609
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy => $"Match a character other than {Literal(node.Ch)} {DescribeLoop(node, rm)}{direction}.",
5610
RegexNodeKind
.One => $"Match {Literal(node.Ch)}{direction}.",
5611
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy => $"Match {Literal(node.Ch)} {DescribeLoop(node, rm)}{direction}.",
5612
RegexNodeKind
.NegativeLookaround => $"Zero-width negative {(rtl ? "lookbehind" : "lookahead")}.",
5613
RegexNodeKind
.Backreference => $"Match the same text as matched by the {DescribeCapture(node.M, rm)}{direction}.",
5614
RegexNodeKind
.PositiveLookaround => $"Zero-width positive {(rtl ? "lookbehind" : "lookahead")}.",
5615
RegexNodeKind
.Set => $"Match {DescribeSet(node.Str!)}{direction}.",
5616
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy => $"Match {DescribeSet(node.Str!)} {DescribeLoop(node, rm)}{direction}.",
5617
RegexNodeKind
.Start => "Match if at the start position.",
5618
RegexNodeKind
.ExpressionConditional => $"Conditionally match one of two expressions depending on whether an initial expression matches.",
5619
RegexNodeKind
.BackreferenceConditional => $"Conditionally match one of two expressions depending on whether the {DescribeCapture(node.M, rm)} matched.",
5620
RegexNodeKind
.UpdateBumpalong => $"Advance the next matching position.",
5771
RegexNodeKind
.Concatenate when node.Parent is not { Kind:
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional } => true,
5774
RegexNodeKind
.Atomic when node.Child(0).Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop or
RegexNodeKind
.Alternate => true,
5777
RegexNodeKind
.UpdateBumpalong => true,
5787
RegexNodeKind
.ExpressionConditional when node.Parent.Child(0) == node => "Condition: ",
5788
RegexNodeKind
.ExpressionConditional when node.Parent.Child(1) == node => "Matched: ",
5789
RegexNodeKind
.ExpressionConditional when node.Parent.Child(2) == node => "Not Matched: ",
5791
RegexNodeKind
.BackreferenceConditional when node.Parent.Child(0) == node => "Matched: ",
5792
RegexNodeKind
.BackreferenceConditional when node.Parent.Child(1) == node => "Not Matched: ",
5832
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloopatomic => "atomically",
5833
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop => "greedily",
5834
RegexNodeKind
.Loop => rm.Analysis.IsAtomicByAncestor(node) ? "atomically" : "greedily",