1299 references to RegexNodeKind
System.Text.RegularExpressions (1299)
System\Text\RegularExpressions\RegexCompiler.cs (123)
512
if (RegexPrefixAnalyzer.FindTrailingAnchor(_regexTree.Root) ==
RegexNodeKind
.End &&
668
case
RegexNodeKind
.Bol:
747
case
RegexNodeKind
.End or
RegexNodeKind
.EndZ when _regexTree.FindOptimizations.MaxPossibleLength is int maxLength:
1268
Debug.Assert(target.LoopNode.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic);
1451
Debug.Assert(node.Kind ==
RegexNodeKind
.Capture, "Every generated tree should begin with a capture node");
1461
case
RegexNodeKind
.Multi or
RegexNodeKind
.Notone or
RegexNodeKind
.One or
RegexNodeKind
.Set:
1467
int length = node.Kind ==
RegexNodeKind
.Multi ? node.Str!.Length : 1;
1667
Debug.Assert(node.Kind is
RegexNodeKind
.Alternate, $"Unexpected type: {node.Kind}");
1872
Debug.Assert(node.Kind is
RegexNodeKind
.Backreference, $"Unexpected type: {node.Kind}");
2047
Debug.Assert(node.Kind is
RegexNodeKind
.BackreferenceConditional, $"Unexpected type: {node.Kind}");
2061
RegexNode? noBranch = node.Child(1) is { Kind: not
RegexNodeKind
.Empty } childNo ? childNo : null;
2206
Debug.Assert(node.Kind is
RegexNodeKind
.ExpressionConditional, $"Unexpected type: {node.Kind}");
2222
RegexNode? noBranch = node.Child(2) is { Kind: not
RegexNodeKind
.Empty } childNo ? childNo : null;
2399
Debug.Assert(node.Kind is
RegexNodeKind
.Capture, $"Unexpected type: {node.Kind}");
2525
Debug.Assert(node.Kind is
RegexNodeKind
.PositiveLookaround, $"Unexpected type: {node.Kind}");
2569
Debug.Assert(node.Kind is
RegexNodeKind
.NegativeLookaround, $"Unexpected type: {node.Kind}");
2720
case
RegexNodeKind
.Beginning:
2721
case
RegexNodeKind
.Start:
2722
case
RegexNodeKind
.Bol:
2723
case
RegexNodeKind
.Eol:
2724
case
RegexNodeKind
.End:
2725
case
RegexNodeKind
.EndZ:
2729
case
RegexNodeKind
.Boundary:
2730
case
RegexNodeKind
.NonBoundary:
2731
case
RegexNodeKind
.ECMABoundary:
2732
case
RegexNodeKind
.NonECMABoundary:
2736
case
RegexNodeKind
.Multi:
2740
case
RegexNodeKind
.One:
2741
case
RegexNodeKind
.Notone:
2742
case
RegexNodeKind
.Set:
2746
case
RegexNodeKind
.Oneloop:
2747
case
RegexNodeKind
.Notoneloop:
2748
case
RegexNodeKind
.Setloop:
2752
case
RegexNodeKind
.Onelazy:
2753
case
RegexNodeKind
.Notonelazy:
2754
case
RegexNodeKind
.Setlazy:
2758
case
RegexNodeKind
.Oneloopatomic:
2759
case
RegexNodeKind
.Notoneloopatomic:
2760
case
RegexNodeKind
.Setloopatomic:
2764
case
RegexNodeKind
.Loop:
2768
case
RegexNodeKind
.Lazyloop:
2772
case
RegexNodeKind
.Alternate:
2776
case
RegexNodeKind
.Concatenate:
2780
case
RegexNodeKind
.Atomic:
2784
case
RegexNodeKind
.Backreference:
2788
case
RegexNodeKind
.BackreferenceConditional:
2792
case
RegexNodeKind
.ExpressionConditional:
2796
case
RegexNodeKind
.Capture:
2800
case
RegexNodeKind
.PositiveLookaround:
2804
case
RegexNodeKind
.NegativeLookaround:
2808
case
RegexNodeKind
.Nothing:
2812
case
RegexNodeKind
.Empty:
2816
case
RegexNodeKind
.UpdateBumpalong:
2828
Debug.Assert(node.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround or
RegexNodeKind
.ExpressionConditional, $"Unexpected type: {node.Kind}");
2829
Debug.Assert(node.Kind is
RegexNodeKind
.ExpressionConditional ? node.ChildCount() >= 1 : node.ChildCount() == 1, $"Unexpected number of children: {node.ChildCount()}");
2835
if (node.Kind is
RegexNodeKind
.Atomic && !analysis.MayBacktrack(child))
2872
Debug.Assert(node.Kind is
RegexNodeKind
.UpdateBumpalong, $"Unexpected type: {node.Kind}");
2892
Debug.Assert(node.Kind is
RegexNodeKind
.Concatenate, $"Unexpected type: {node.Kind}");
2950
if (next.Kind is not
RegexNodeKind
.UpdateBumpalong) // skip node types that don't have a semantic impact
3038
Debug.Assert(node.Kind is
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary or
RegexNodeKind
.ECMABoundary or
RegexNodeKind
.NonECMABoundary, $"Unexpected type: {node.Kind}");
3056
case
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary:
3070
if (node.Kind is
RegexNodeKind
.Boundary)
3083
if (node.Kind is
RegexNodeKind
.ECMABoundary)
3098
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}");
3105
case
RegexNodeKind
.Beginning:
3106
case
RegexNodeKind
.Start:
3117
if (node.Kind ==
RegexNodeKind
.Beginning)
3129
case
RegexNodeKind
.Bol:
3160
case
RegexNodeKind
.End:
3177
case
RegexNodeKind
.EndZ:
3194
goto case
RegexNodeKind
.Eol;
3196
case
RegexNodeKind
.Eol:
3236
Debug.Assert(node.Kind is
RegexNodeKind
.Multi, $"Unexpected type: {node.Kind}");
3288
Debug.Assert(node.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop, $"Unexpected type: {node.Kind}");
3504
Debug.Assert(node.Kind is
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy, $"Unexpected type: {node.Kind}");
3605
node.Kind is
RegexNodeKind
.Notonelazy &&
3746
node.Kind is
RegexNodeKind
.Setlazy &&
3851
Debug.Assert(node.Kind is
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
4362
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}");
4609
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}");
4698
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
4736
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop, $"Unexpected type: {node.Kind}");
5134
if (node.Kind ==
RegexNodeKind
.Multi)
5167
if (node.Kind ==
RegexNodeKind
.Multi)
5360
if (root.Kind is
RegexNodeKind
.Multi or
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set)
5378
Ldc((root.Kind ==
RegexNodeKind
.Multi ? root.Str!.Length : 1) * (!rtl ? 1 : -1));
System\Text\RegularExpressions\RegexFindOptimizations.cs (23)
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; }
409
Debug.Assert(LeadingAnchor !=
RegexNodeKind
.Bol, "BOL isn't enabled for RTL");
535
if (LeadingAnchor ==
RegexNodeKind
.Bol)
822
Debug.Assert(loopNode.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic);
System\Text\RegularExpressions\RegexNode.cs (718)
23
public
RegexNodeKind
Kind { get; private set; }
26
/// <remarks>For a <see cref="
RegexNodeKind
.Multi"/>, this is the string from the expression. For an <see cref="IsSetFamily"/> node, this is the character class string from <see cref="RegexCharClass"/>.</remarks>
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;
243
Debug.Assert(Kind ==
RegexNodeKind
.Capture, "Every generated tree should begin with a capture node");
262
Debug.Assert(Kind !=
RegexNodeKind
.Group, "All Group nodes should have been removed.");
267
case
RegexNodeKind
.Group:
271
case
RegexNodeKind
.Beginning:
272
case
RegexNodeKind
.Bol:
273
case
RegexNodeKind
.Boundary:
274
case
RegexNodeKind
.ECMABoundary:
275
case
RegexNodeKind
.Empty:
276
case
RegexNodeKind
.End:
277
case
RegexNodeKind
.EndZ:
278
case
RegexNodeKind
.Eol:
279
case
RegexNodeKind
.Multi:
280
case
RegexNodeKind
.NonBoundary:
281
case
RegexNodeKind
.NonECMABoundary:
282
case
RegexNodeKind
.Nothing:
283
case
RegexNodeKind
.Notone:
284
case
RegexNodeKind
.Notonelazy:
285
case
RegexNodeKind
.Notoneloop:
286
case
RegexNodeKind
.Notoneloopatomic:
287
case
RegexNodeKind
.One:
288
case
RegexNodeKind
.Onelazy:
289
case
RegexNodeKind
.Oneloop:
290
case
RegexNodeKind
.Oneloopatomic:
291
case
RegexNodeKind
.Backreference:
292
case
RegexNodeKind
.Set:
293
case
RegexNodeKind
.Setlazy:
294
case
RegexNodeKind
.Setloop:
295
case
RegexNodeKind
.Setloopatomic:
296
case
RegexNodeKind
.Start:
297
case
RegexNodeKind
.UpdateBumpalong:
301
case
RegexNodeKind
.Atomic:
302
case
RegexNodeKind
.Capture:
303
case
RegexNodeKind
.Lazyloop:
304
case
RegexNodeKind
.Loop:
305
case
RegexNodeKind
.NegativeLookaround:
306
case
RegexNodeKind
.PositiveLookaround:
310
case
RegexNodeKind
.BackreferenceConditional:
314
case
RegexNodeKind
.ExpressionConditional:
318
case
RegexNodeKind
.Concatenate:
319
case
RegexNodeKind
.Alternate:
331
case
RegexNodeKind
.Multi:
336
case
RegexNodeKind
.Set:
337
case
RegexNodeKind
.Setloop:
338
case
RegexNodeKind
.Setloopatomic:
339
case
RegexNodeKind
.Setlazy:
351
case
RegexNodeKind
.Backreference:
372
Debug.Assert(rootNode.Kind ==
RegexNodeKind
.Capture);
415
case
RegexNodeKind
.Atomic:
419
case
RegexNodeKind
.Concatenate:
424
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when node.N == int.MaxValue:
425
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when node.N == int.MaxValue && !atomicByAncestry:
426
if (node.Parent is { Kind:
RegexNodeKind
.Concatenate } parent)
428
parent.InsertChild(1, new RegexNode(
RegexNodeKind
.UpdateBumpalong, node.Options));
476
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop:
477
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy:
483
case
RegexNodeKind
.Atomic:
484
case
RegexNodeKind
.PositiveLookaround:
485
case
RegexNodeKind
.NegativeLookaround:
495
case
RegexNodeKind
.Capture:
496
case
RegexNodeKind
.Concatenate when !rtl:
498
if ((existingChild.Kind is
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop) &&
499
node.Parent is not { Kind:
RegexNodeKind
.Atomic }) // validate grandparent isn't atomic
501
var atomic = new RegexNode(
RegexNodeKind
.Atomic, existingChild.Options);
511
case
RegexNodeKind
.Alternate:
512
case
RegexNodeKind
.BackreferenceConditional:
513
case
RegexNodeKind
.ExpressionConditional:
521
if (node.Kind !=
RegexNodeKind
.ExpressionConditional) // ReduceExpressionConditional will have already applied ending backtracking removal
536
case
RegexNodeKind
.Lazyloop:
537
case
RegexNodeKind
.Loop:
542
Debug.Assert(node.Kind is
RegexNodeKind
.Atomic or
RegexNodeKind
.Empty or
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
544
if (node.Kind is
RegexNodeKind
.Atomic)
547
Debug.Assert(node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
550
if (node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop)
584
case
RegexNodeKind
.Backreference:
591
RegexNodeKind
.Alternate => ReduceAlternation(),
592
RegexNodeKind
.Atomic => ReduceAtomic(),
593
RegexNodeKind
.Concatenate => ReduceConcatenation(),
594
RegexNodeKind
.Group => ReduceGroup(),
595
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop => ReduceLoops(),
596
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround => ReduceLookaround(),
597
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy => ReduceSet(),
598
RegexNodeKind
.ExpressionConditional => ReduceExpressionConditional(),
599
RegexNodeKind
.BackreferenceConditional => ReduceBackreferenceConditional(),
612
Debug.Assert(Kind is
RegexNodeKind
.Alternate or
RegexNodeKind
.Concatenate);
615
0 => new RegexNode(Kind ==
RegexNodeKind
.Alternate ?
RegexNodeKind
.Nothing :
RegexNodeKind
.Empty, Options),
629
Debug.Assert(Kind ==
RegexNodeKind
.Group);
632
while (u.Kind ==
RegexNodeKind
.Group)
657
Debug.Assert(Kind ==
RegexNodeKind
.Atomic);
662
while (child.Kind ==
RegexNodeKind
.Atomic)
672
case
RegexNodeKind
.Empty:
673
case
RegexNodeKind
.Nothing:
677
case
RegexNodeKind
.Oneloopatomic:
678
case
RegexNodeKind
.Notoneloopatomic:
679
case
RegexNodeKind
.Setloopatomic:
684
case
RegexNodeKind
.Oneloop:
685
case
RegexNodeKind
.Notoneloop:
686
case
RegexNodeKind
.Setloop:
687
case
RegexNodeKind
.Onelazy:
688
case
RegexNodeKind
.Notonelazy:
689
case
RegexNodeKind
.Setlazy:
695
case
RegexNodeKind
.Alternate:
704
if (branches[0].Kind ==
RegexNodeKind
.Empty)
706
return new RegexNode(
RegexNodeKind
.Empty, child.Options);
715
if (branches[i].Kind ==
RegexNodeKind
.Empty)
796
(child.Child(0).Kind is
RegexNodeKind
.Empty || child.Child(1).Kind is
RegexNodeKind
.Empty); // can be transformed into a ? or ??
811
return child.Kind ==
RegexNodeKind
.Empty ?
826
Debug.Assert(Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop);
829
RegexNodeKind
kind = Kind;
842
if (kind ==
RegexNodeKind
.Loop)
846
case
RegexNodeKind
.Oneloop:
847
case
RegexNodeKind
.Oneloopatomic:
848
case
RegexNodeKind
.Notoneloop:
849
case
RegexNodeKind
.Notoneloopatomic:
850
case
RegexNodeKind
.Setloop:
851
case
RegexNodeKind
.Setloopatomic:
860
case
RegexNodeKind
.Onelazy:
861
case
RegexNodeKind
.Notonelazy:
862
case
RegexNodeKind
.Setlazy:
896
return new RegexNode(
RegexNodeKind
.Nothing, Options);
907
case
RegexNodeKind
.One:
908
case
RegexNodeKind
.Notone:
909
case
RegexNodeKind
.Set:
910
child.MakeRep(u.Kind ==
RegexNodeKind
.Lazyloop ?
RegexNodeKind
.Onelazy :
RegexNodeKind
.Oneloop, u.M, u.N);
914
case
RegexNodeKind
.Empty:
919
case
RegexNodeKind
.PositiveLookaround when ContainsKind(child, [
RegexNodeKind
.Capture]) is false:
920
case
RegexNodeKind
.NegativeLookaround or
921
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
922
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
923
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
924
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
925
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary:
935
u = u.M == 0 ? new RegexNode(
RegexNodeKind
.Empty, Options) : child;
958
Debug.Assert(Kind is
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy);
963
Kind =
RegexNodeKind
.Nothing;
971
Kind ==
RegexNodeKind
.Set ?
RegexNodeKind
.One :
972
Kind ==
RegexNodeKind
.Setloop ?
RegexNodeKind
.Oneloop :
973
Kind ==
RegexNodeKind
.Setloopatomic ?
RegexNodeKind
.Oneloopatomic :
974
RegexNodeKind
.Onelazy;
981
Kind ==
RegexNodeKind
.Set ?
RegexNodeKind
.Notone :
982
Kind ==
RegexNodeKind
.Setloop ?
RegexNodeKind
.Notoneloop :
983
Kind ==
RegexNodeKind
.Setloopatomic ?
RegexNodeKind
.Notoneloopatomic :
984
RegexNodeKind
.Notonelazy;
1018
Debug.Assert(Kind ==
RegexNodeKind
.Alternate);
1023
return new RegexNode(
RegexNodeKind
.Nothing, Options);
1031
if (node.Kind ==
RegexNodeKind
.Alternate)
1034
if (node.Kind ==
RegexNodeKind
.Alternate)
1037
if (node.Kind ==
RegexNodeKind
.Alternate)
1045
if (node.Kind is
RegexNodeKind
.Alternate && node.ChildCount() == 2)
1047
if (node.Child(1).Kind is
RegexNodeKind
.Empty)
1051
else if (node.Child(0).Kind is
RegexNodeKind
.Empty)
1088
if (at.Kind ==
RegexNodeKind
.Alternate)
1106
else if (at.Kind is
RegexNodeKind
.Set or
RegexNodeKind
.One)
1111
if (at.Kind ==
RegexNodeKind
.Set)
1135
if (prev.Kind ==
RegexNodeKind
.One)
1145
if (at.Kind ==
RegexNodeKind
.One)
1155
prev.Kind =
RegexNodeKind
.Set;
1162
else if (at.Kind ==
RegexNodeKind
.Nothing)
1186
Debug.Assert(alternation.Kind ==
RegexNodeKind
.Alternate);
1199
if (child.Kind !=
RegexNodeKind
.Concatenate || child.ChildCount() < 2)
1216
case
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set:
1217
case
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloopatomic:
1218
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when required.M == required.N:
1219
case
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
RegexNodeKind
.Bol
1220
or
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol
1221
or
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary
1222
or
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary:
1252
var newAlternate = new RegexNode(
RegexNodeKind
.Alternate, alternation.Options);
1260
if (alternation.Parent is RegexNode { Kind:
RegexNodeKind
.Atomic })
1262
var atomic = new RegexNode(
RegexNodeKind
.Atomic, alternation.Options);
1269
var newConcat = new RegexNode(
RegexNodeKind
.Concatenate, alternation.Options);
1285
Debug.Assert(node.Kind ==
RegexNodeKind
.Alternate);
1296
case
RegexNodeKind
.Empty when !seenEmpty:
1300
case
RegexNodeKind
.Empty:
1301
case
RegexNodeKind
.Nothing:
1328
Debug.Assert(alternation.Kind ==
RegexNodeKind
.Alternate);
1355
if (startingNode.Kind ==
RegexNodeKind
.One)
1375
if (startingNode.Kind ==
RegexNodeKind
.One)
1389
Debug.Assert(startingNode.Kind ==
RegexNodeKind
.Multi);
1420
new RegexNode(
RegexNodeKind
.One, startingNodeOptions, startingSpan[0]) :
1421
new RegexNode(
RegexNodeKind
.Multi, startingNodeOptions, startingSpan.ToString());
1422
var newAlternate = new RegexNode(
RegexNodeKind
.Alternate, startingNodeOptions);
1426
ProcessOneOrMulti(branch.Kind ==
RegexNodeKind
.Concatenate ? branch.Child(0) : branch, startingSpan);
1434
if (node.Kind ==
RegexNodeKind
.One)
1438
node.Kind =
RegexNodeKind
.Empty;
1443
Debug.Assert(node.Kind ==
RegexNodeKind
.Multi);
1447
node.Kind =
RegexNodeKind
.Empty;
1452
node.Kind =
RegexNodeKind
.One;
1464
if (alternation.Parent is RegexNode parent && parent.Kind ==
RegexNodeKind
.Atomic)
1466
var atomic = new RegexNode(
RegexNodeKind
.Atomic, startingNodeOptions);
1471
var newConcat = new RegexNode(
RegexNodeKind
.Concatenate, startingNodeOptions);
1491
RegexNode branch = Kind ==
RegexNodeKind
.Concatenate ? Child(0) : this;
1492
return branch.Kind is
RegexNodeKind
.One or
RegexNodeKind
.Multi ? branch : null;
1498
Debug.Assert(Kind is
RegexNodeKind
.One or
RegexNodeKind
.Multi || (IsOneFamily && M > 0));
1513
case
RegexNodeKind
.One:
1514
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy when node.M > 0:
1515
case
RegexNodeKind
.Notone:
1516
case
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy when node.M > 0:
1517
case
RegexNodeKind
.Set:
1518
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy when node.M > 0:
1519
case
RegexNodeKind
.Multi:
1522
case
RegexNodeKind
.Atomic:
1523
case
RegexNodeKind
.Concatenate:
1524
case
RegexNodeKind
.Capture:
1525
case
RegexNodeKind
.Group:
1526
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M > 0:
1527
case
RegexNodeKind
.PositiveLookaround when allowZeroWidth:
1548
case
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy:
1551
case
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy:
1554
case
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy:
1570
case
RegexNodeKind
.Multi:
1613
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1619
return new RegexNode(
RegexNodeKind
.Empty, Options);
1629
if (child.Kind ==
RegexNodeKind
.Nothing)
1655
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1672
if (at.Kind ==
RegexNodeKind
.Concatenate &&
1691
else if (at.Kind is
RegexNodeKind
.Multi or
RegexNodeKind
.One)
1705
if (prev.Kind ==
RegexNodeKind
.One)
1707
prev.Kind =
RegexNodeKind
.Multi;
1712
((at.Kind ==
RegexNodeKind
.One) ? $"{prev.Str}{at.Ch}" : prev.Str + at.Str) :
1713
((at.Kind ==
RegexNodeKind
.One) ? $"{at.Ch}{prev.Str}" : at.Str + prev.Str);
1715
else if (at.Kind ==
RegexNodeKind
.Empty)
1738
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate);
1776
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:
1777
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy when nextNode.Kind == currentNode.Kind && currentNode.Str == nextNode.Str:
1779
currentNode.Kind is
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Setloopatomic)
1802
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy when nextNode.Kind ==
RegexNodeKind
.One && currentNode.Ch == nextNode.Ch:
1803
case
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notonelazy when nextNode.Kind ==
RegexNodeKind
.Notone && currentNode.Ch == nextNode.Ch:
1804
case
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy when nextNode.Kind ==
RegexNodeKind
.Set && currentNode.Str == nextNode.Str:
1818
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy when
1819
nextNode.Kind ==
RegexNodeKind
.Multi &&
1852
nextNode.Kind =
RegexNodeKind
.One;
1870
case
RegexNodeKind
.One when (nextNode.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy) && currentNode.Ch == nextNode.Ch:
1871
case
RegexNodeKind
.Notone when (nextNode.Kind is
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy) && currentNode.Ch == nextNode.Ch:
1872
case
RegexNodeKind
.Set when (nextNode.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy) && currentNode.Str == nextNode.Str:
1885
case
RegexNodeKind
.Notone when nextNode.Kind == currentNode.Kind && currentNode.Ch == nextNode.Ch:
1886
case
RegexNodeKind
.Set when nextNode.Kind ==
RegexNodeKind
.Set && currentNode.Str == nextNode.Str:
1887
currentNode.MakeRep(
RegexNodeKind
.Oneloop, 2, 2);
1892
case
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
1893
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
1894
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
1895
RegexNodeKind
.Boundary or
RegexNodeKind
.NonBoundary or
1896
RegexNodeKind
.ECMABoundary or
RegexNodeKind
.NonECMABoundary
1940
if (Kind is not
RegexNodeKind
.Concatenate)
1964
while (node.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
1972
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: true, allowLazy: false):
1981
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: false, allowLazy: true):
1997
node.Kind -=
RegexNodeKind
.Onelazy -
RegexNodeKind
.Oneloop; // lazy to greedy
2001
case
RegexNodeKind
.Loop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: true, allowLazy: false):
2002
case
RegexNodeKind
.Lazyloop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: false, allowLazy: true):
2016
while (loopChild.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
2022
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
2023
RegexNodeKind
.Multi or
2024
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set)
2029
else if (node.Kind is
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop)
2033
goto case
RegexNodeKind
.Loop;
2041
case
RegexNodeKind
.Loop:
2051
case
RegexNodeKind
.Lazyloop:
2061
case
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional:
2072
for (int b = node.Kind ==
RegexNodeKind
.ExpressionConditional ? 1 : 0; b < alternateBranches; b++)
2086
Debug.Assert(Kind is
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround);
2094
if (Kind is
RegexNodeKind
.NegativeLookaround && ContainsKind(Child(0), [
RegexNodeKind
.Backreference,
RegexNodeKind
.BackreferenceConditional]) is false)
2109
if (node is { Kind:
RegexNodeKind
.Capture, N: -1 })
2140
if (Kind is
RegexNodeKind
.PositiveLookaround)
2143
child.Kind is
RegexNodeKind
.Empty)
2148
else if (Kind is
RegexNodeKind
.NegativeLookaround)
2153
if (child.Kind is
RegexNodeKind
.Empty)
2155
Kind =
RegexNodeKind
.Nothing;
2163
private static bool IsZeroWidthAssertion(
RegexNodeKind
kind) => kind is
2164
RegexNodeKind
.PositiveLookaround or
RegexNodeKind
.NegativeLookaround or
2165
RegexNodeKind
.Beginning or
RegexNodeKind
.Start or
2166
RegexNodeKind
.Bol or
RegexNodeKind
.Eol or
2167
RegexNodeKind
.End or
RegexNodeKind
.EndZ or
2168
RegexNodeKind
.Boundary or
RegexNodeKind
.ECMABoundary or
2169
RegexNodeKind
.NonBoundary or
RegexNodeKind
.NonECMABoundary or
2170
RegexNodeKind
.UpdateBumpalong;
2174
private static bool? ContainsKind(RegexNode node, ReadOnlySpan<
RegexNodeKind
> kinds)
2176
foreach (
RegexNodeKind
kind in kinds)
2206
Debug.Assert(Kind ==
RegexNodeKind
.BackreferenceConditional);
2215
AddChild(new RegexNode(
RegexNodeKind
.Empty, Options));
2224
Debug.Assert(Kind ==
RegexNodeKind
.ExpressionConditional);
2233
AddChild(new RegexNode(
RegexNodeKind
.Empty, Options));
2242
if (condition.Kind ==
RegexNodeKind
.PositiveLookaround && (condition.Options & RegexOptions.RightToLeft) == 0)
2269
while (node.Kind is
RegexNodeKind
.Capture or
RegexNodeKind
.Concatenate)
2287
case
RegexNodeKind
.Concatenate:
2288
case
RegexNodeKind
.Capture:
2289
case
RegexNodeKind
.Atomic:
2293
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when subsequent.M > 0:
2301
case
RegexNodeKind
.PositiveLookaround when (subsequent.Options & RegexOptions.RightToLeft) == 0:
2325
case
RegexNodeKind
.Alternate:
2326
case
RegexNodeKind
.ExpressionConditional when childCount is 3: // condition, yes, and no branch
2341
case
RegexNodeKind
.Oneloop:
2342
case
RegexNodeKind
.Onelazy when allowLazy:
2345
case
RegexNodeKind
.One when node.Ch != subsequent.Ch:
2346
case
RegexNodeKind
.Notone when node.Ch == subsequent.Ch:
2347
case
RegexNodeKind
.Set when !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2348
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && node.Ch != subsequent.Ch:
2349
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch:
2350
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2351
case
RegexNodeKind
.Multi when node.Ch != subsequent.Str![0]:
2352
case
RegexNodeKind
.End:
2353
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when node.Ch != '\n':
2354
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsBoundaryWordChar(node.Ch):
2355
case
RegexNodeKind
.NonBoundary when node.M > 0 && !RegexCharClass.IsBoundaryWordChar(node.Ch):
2356
case
RegexNodeKind
.ECMABoundary when node.M > 0 && RegexCharClass.IsECMAWordChar(node.Ch):
2357
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && !RegexCharClass.IsECMAWordChar(node.Ch):
2360
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && node.Ch != subsequent.Ch:
2361
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch:
2362
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!):
2371
case
RegexNodeKind
.Notoneloop:
2372
case
RegexNodeKind
.Notonelazy when allowLazy:
2375
case
RegexNodeKind
.One when node.Ch == subsequent.Ch:
2376
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch:
2377
case
RegexNodeKind
.Multi when node.Ch == subsequent.Str![0]:
2378
case
RegexNodeKind
.End:
2381
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch:
2390
case
RegexNodeKind
.Setloop:
2391
case
RegexNodeKind
.Setlazy when allowLazy:
2394
case
RegexNodeKind
.One when !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2395
case
RegexNodeKind
.Set when !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2396
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2397
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2398
case
RegexNodeKind
.Multi when !RegexCharClass.CharInClass(subsequent.Str![0], node.Str!):
2399
case
RegexNodeKind
.End:
2400
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when !RegexCharClass.CharInClass('\n', node.Str!):
2401
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsKnownWordClassSubset(node.Str!):
2402
case
RegexNodeKind
.NonBoundary when node.M > 0 && node.Str is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass:
2403
case
RegexNodeKind
.ECMABoundary when node.M > 0 && node.Str is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass:
2404
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && node.Str is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass:
2407
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
2408
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
2417
case
RegexNodeKind
.Loop:
2418
case
RegexNodeKind
.Lazyloop when allowLazy:
2441
case
RegexNodeKind
.One when !CharInStartingOrEndingSet(subsequent.Ch):
2442
case
RegexNodeKind
.Set when !MayOverlapStartingOrEndingSet(subsequent.Str!):
2443
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M > 0 && !CharInStartingOrEndingSet(subsequent.Ch):
2444
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M > 0 && !MayOverlapStartingOrEndingSet(subsequent.Str!):
2445
case
RegexNodeKind
.Multi when !CharInStartingOrEndingSet(subsequent.Str![0]):
2446
case
RegexNodeKind
.End:
2447
case
RegexNodeKind
.EndZ or
RegexNodeKind
.Eol when !CharInStartingOrEndingSet('\n'):
2448
case
RegexNodeKind
.Boundary when node.M > 0 && RegexCharClass.IsKnownWordClassSubset(loopStartingSet) && RegexCharClass.IsKnownWordClassSubset(loopEndingSet):
2449
case
RegexNodeKind
.NonBoundary when node.M > 0 && (loopStartingSet is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass) && (loopEndingSet is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass):
2450
case
RegexNodeKind
.ECMABoundary when node.M > 0 && (loopStartingSet is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass) && (loopEndingSet is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass):
2451
case
RegexNodeKind
.NonECMABoundary when node.M > 0 && (loopStartingSet is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass) && (loopEndingSet is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass):
2454
case
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic when subsequent.M == 0 && !CharInStartingOrEndingSet(subsequent.Ch):
2455
case
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic when subsequent.M == 0 && !MayOverlapStartingOrEndingSet(subsequent.Str!):
2483
case
RegexNodeKind
.Atomic:
2484
case
RegexNodeKind
.Alternate:
2485
case
RegexNodeKind
.Capture:
2489
case
RegexNodeKind
.Concatenate:
2528
Debug.Assert(node.Kind is not
RegexNodeKind
.Concatenate, "The existing logic assumes that the node itself isn't a concatenation.");
2541
case
RegexNodeKind
.Atomic:
2542
case
RegexNodeKind
.Alternate:
2543
case
RegexNodeKind
.Capture:
2547
case
RegexNodeKind
.Concatenate:
2583
case
RegexNodeKind
.One:
2584
case
RegexNodeKind
.Notone:
2585
case
RegexNodeKind
.Set:
2589
case
RegexNodeKind
.Multi:
2593
case
RegexNodeKind
.Notonelazy:
2594
case
RegexNodeKind
.Notoneloop:
2595
case
RegexNodeKind
.Notoneloopatomic:
2596
case
RegexNodeKind
.Onelazy:
2597
case
RegexNodeKind
.Oneloop:
2598
case
RegexNodeKind
.Oneloopatomic:
2599
case
RegexNodeKind
.Setlazy:
2600
case
RegexNodeKind
.Setloop:
2601
case
RegexNodeKind
.Setloopatomic:
2605
case
RegexNodeKind
.Lazyloop:
2606
case
RegexNodeKind
.Loop:
2610
case
RegexNodeKind
.Alternate:
2623
case
RegexNodeKind
.BackreferenceConditional:
2627
case
RegexNodeKind
.ExpressionConditional:
2631
case
RegexNodeKind
.Concatenate:
2643
case
RegexNodeKind
.Atomic:
2644
case
RegexNodeKind
.Capture:
2645
case
RegexNodeKind
.Group:
2650
case
RegexNodeKind
.Empty:
2651
case
RegexNodeKind
.Nothing:
2652
case
RegexNodeKind
.UpdateBumpalong:
2656
case
RegexNodeKind
.Beginning:
2657
case
RegexNodeKind
.Bol:
2658
case
RegexNodeKind
.Boundary:
2659
case
RegexNodeKind
.ECMABoundary:
2660
case
RegexNodeKind
.End:
2661
case
RegexNodeKind
.EndZ:
2662
case
RegexNodeKind
.Eol:
2663
case
RegexNodeKind
.NonBoundary:
2664
case
RegexNodeKind
.NonECMABoundary:
2665
case
RegexNodeKind
.Start:
2666
case
RegexNodeKind
.NegativeLookaround:
2667
case
RegexNodeKind
.PositiveLookaround:
2669
case
RegexNodeKind
.Backreference:
2677
goto case
RegexNodeKind
.Empty;
2696
case
RegexNodeKind
.One:
2697
case
RegexNodeKind
.Notone:
2698
case
RegexNodeKind
.Set:
2702
case
RegexNodeKind
.Multi:
2706
case
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
2707
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
2708
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic:
2712
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop:
2727
case
RegexNodeKind
.Alternate:
2750
case
RegexNodeKind
.BackreferenceConditional:
2751
case
RegexNodeKind
.ExpressionConditional:
2754
int i = Kind ==
RegexNodeKind
.BackreferenceConditional ? 0 : 1;
2760
case
RegexNodeKind
.Concatenate:
2782
case
RegexNodeKind
.Atomic:
2783
case
RegexNodeKind
.Capture:
2788
case
RegexNodeKind
.Empty:
2789
case
RegexNodeKind
.Nothing:
2790
case
RegexNodeKind
.UpdateBumpalong:
2791
case
RegexNodeKind
.Beginning:
2792
case
RegexNodeKind
.Bol:
2793
case
RegexNodeKind
.Boundary:
2794
case
RegexNodeKind
.ECMABoundary:
2795
case
RegexNodeKind
.End:
2796
case
RegexNodeKind
.EndZ:
2797
case
RegexNodeKind
.Eol:
2798
case
RegexNodeKind
.NonBoundary:
2799
case
RegexNodeKind
.NonECMABoundary:
2800
case
RegexNodeKind
.Start:
2801
case
RegexNodeKind
.PositiveLookaround:
2802
case
RegexNodeKind
.NegativeLookaround:
2806
case
RegexNodeKind
.Backreference:
2814
goto case
RegexNodeKind
.Empty;
2837
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate, $"Expected Concatenate, got {Kind}");
2850
if (child.Kind is
RegexNodeKind
.One)
2863
else if (child.Kind is
RegexNodeKind
.Multi)
2875
else if (child.Kind is
RegexNodeKind
.Set ||
2876
(child.Kind is
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic && child.M == child.N))
2885
vsb.Append((char)(twoChars[0] | 0x20), child.Kind is
RegexNodeKind
.Set ? 1 : child.M);
2887
else if (child.Kind is
RegexNodeKind
.Empty)
2938
Debug.Assert(Kind ==
RegexNodeKind
.Concatenate, $"Expected Concatenate, got {Kind}");
2942
RegexNodeKind
.One or
RegexNodeKind
.Notone or
RegexNodeKind
.Set => true,
2943
RegexNodeKind
.Multi => true,
2944
RegexNodeKind
.Oneloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Oneloopatomic or
2945
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Notoneloopatomic or
2946
RegexNodeKind
.Setloop or
RegexNodeKind
.Setlazy or
RegexNodeKind
.Setloopatomic
2988
return new RegexNode(
RegexNodeKind
.Empty, Options);
2994
case <= MultiVsRepeaterLimit when Kind ==
RegexNodeKind
.One:
3000
Kind =
RegexNodeKind
.Multi;
3009
case
RegexNodeKind
.One:
3010
case
RegexNodeKind
.Notone:
3011
case
RegexNodeKind
.Set:
3012
MakeRep(lazy ?
RegexNodeKind
.Onelazy :
RegexNodeKind
.Oneloop, min, max);
3016
var result = new RegexNode(lazy ?
RegexNodeKind
.Lazyloop :
RegexNodeKind
.Loop, Options, min, max);
3139
public bool IsSetFamily => Kind is
RegexNodeKind
.Set or
RegexNodeKind
.Setloop or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Setlazy;
3142
public bool IsOneFamily => Kind is
RegexNodeKind
.One or
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy;
3145
public bool IsNotoneFamily => Kind is
RegexNodeKind
.Notone or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Notoneloopatomic or
RegexNodeKind
.Notonelazy;
3196
case
RegexNodeKind
.Oneloop:
3197
case
RegexNodeKind
.Oneloopatomic:
3198
case
RegexNodeKind
.Notoneloop:
3199
case
RegexNodeKind
.Notoneloopatomic:
3200
case
RegexNodeKind
.Onelazy:
3201
case
RegexNodeKind
.Notonelazy:
3202
case
RegexNodeKind
.One:
3203
case
RegexNodeKind
.Notone:
3206
case
RegexNodeKind
.Capture:
3213
case
RegexNodeKind
.Backreference:
3214
case
RegexNodeKind
.BackreferenceConditional:
3217
case
RegexNodeKind
.Multi:
3225
case
RegexNodeKind
.Set:
3226
case
RegexNodeKind
.Setloop:
3227
case
RegexNodeKind
.Setloopatomic:
3228
case
RegexNodeKind
.Setlazy:
3235
case
RegexNodeKind
.Oneloop:
3236
case
RegexNodeKind
.Oneloopatomic:
3237
case
RegexNodeKind
.Notoneloop:
3238
case
RegexNodeKind
.Notoneloopatomic:
3239
case
RegexNodeKind
.Onelazy:
3240
case
RegexNodeKind
.Notonelazy:
3241
case
RegexNodeKind
.Setloop:
3242
case
RegexNodeKind
.Setloopatomic:
3243
case
RegexNodeKind
.Setlazy:
3244
case
RegexNodeKind
.Loop:
3245
case
RegexNodeKind
.Lazyloop:
System\Text\RegularExpressions\RegexParser.cs (60)
277
StartGroup(new RegexNode(
RegexNodeKind
.Capture, (_options & ~RegexOptions.IgnoreCase), 0, -1));
347
_unit = new RegexNode(
RegexNodeKind
.Set, _options & ~RegexOptions.IgnoreCase, setString);
394
_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ?
RegexNodeKind
.Bol :
RegexNodeKind
.Beginning, _options);
398
_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ?
RegexNodeKind
.Eol :
RegexNodeKind
.EndZ, _options);
403
new RegexNode(
RegexNodeKind
.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.AnyClass) :
404
new RegexNode(
RegexNodeKind
.Notone, _options & ~RegexOptions.IgnoreCase, '\n');
521
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
759
return new RegexNode(
RegexNodeKind
.Group, _options);
763
return new RegexNode(
RegexNodeKind
.Capture, _options, _autocap++, -1);
776
RegexNodeKind
nodeType;
783
nodeType =
RegexNodeKind
.Group;
789
nodeType =
RegexNodeKind
.PositiveLookaround;
795
nodeType =
RegexNodeKind
.NegativeLookaround;
800
nodeType =
RegexNodeKind
.Atomic;
823
nodeType =
RegexNodeKind
.PositiveLookaround;
834
nodeType =
RegexNodeKind
.NegativeLookaround;
937
return new RegexNode(
RegexNodeKind
.Capture, _options, capnum, uncapnum);
959
return new RegexNode(
RegexNodeKind
.BackreferenceConditional, _options, capnum);
973
return new RegexNode(
RegexNodeKind
.BackreferenceConditional, _options, tmpCapnum);
978
nodeType =
RegexNodeKind
.ExpressionConditional;
1002
nodeType =
RegexNodeKind
.Group;
1004
if (_group!.Kind !=
RegexNodeKind
.ExpressionConditional)
1096
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMAWordClass : RegexCharClass.WordClass);
1101
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMAWordClass : RegexCharClass.NotWordClass);
1106
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMASpaceClass : RegexCharClass.SpaceClass);
1111
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMASpaceClass : RegexCharClass.NotSpaceClass);
1116
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMADigitClass : RegexCharClass.DigitClass);
1121
new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMADigitClass : RegexCharClass.NotDigitClass);
1138
return new RegexNode(
RegexNodeKind
.Set, (_options & ~RegexOptions.IgnoreCase), cc.ToStringClass());
1142
if (result != null && result.Kind ==
RegexNodeKind
.Backreference && (result.Options & RegexOptions.IgnoreCase) != 0)
1203
IsCaptureSlot(capnum) ? new RegexNode(
RegexNodeKind
.Backreference, _options, capnum) :
1235
return scanOnly ? null : new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1249
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1269
_capnames?[capname] is int tmpCapnum ? new RegexNode(
RegexNodeKind
.Backreference, _options, tmpCapnum) :
1345
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1355
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1367
return new RegexNode(
RegexNodeKind
.Backreference, _options, tmpCapnum);
1405
return new RegexNode(
RegexNodeKind
.Backreference, _options, capnum);
1653
private readonly
RegexNodeKind
TypeFromCode(char ch) =>
1656
'b' => (_options & RegexOptions.ECMAScript) != 0 ?
RegexNodeKind
.ECMABoundary :
RegexNodeKind
.Boundary,
1657
'B' => (_options & RegexOptions.ECMAScript) != 0 ?
RegexNodeKind
.NonECMABoundary :
RegexNodeKind
.NonBoundary,
1658
'A' =>
RegexNodeKind
.Beginning,
1659
'G' =>
RegexNodeKind
.Start,
1660
'Z' =>
RegexNodeKind
.EndZ,
1661
'z' =>
RegexNodeKind
.End,
1662
_ =>
RegexNodeKind
.Nothing,
2004
_concatenation!.AddChild(new RegexNode(
RegexNodeKind
.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch)));
2034
if (_group.Kind ==
RegexNodeKind
.ExpressionConditional && _group.ChildCount() == 0)
2050
_alternation = new RegexNode(
RegexNodeKind
.Alternate, _options);
2051
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
2059
if (_group!.Kind is
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.BackreferenceConditional)
2068
_concatenation = new RegexNode(
RegexNodeKind
.Concatenate, _options);
2074
if (_group!.Kind is
RegexNodeKind
.ExpressionConditional or
RegexNodeKind
.BackreferenceConditional)
2078
if (_group.Kind ==
RegexNodeKind
.BackreferenceConditional && _group.ChildCount() > 2 || _group.ChildCount() > 3)
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;
System\Text\RegularExpressions\RegexReplacement.cs (4)
36
Debug.Assert(concat.Kind ==
RegexNodeKind
.Concatenate, $"Expected Concatenate, got {concat.Kind}");
50
case
RegexNodeKind
.Multi:
54
case
RegexNodeKind
.One:
58
case
RegexNodeKind
.Backreference:
System\Text\RegularExpressions\RegexTreeAnalyzer.cs (25)
49
case
RegexNodeKind
.Alternate:
50
case
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.M != node.N:
51
case
RegexNodeKind
.Oneloop or
RegexNodeKind
.Notoneloop or
RegexNodeKind
.Setloop or
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy or
RegexNodeKind
.Setlazy when node.M != node.N:
63
case
RegexNodeKind
.Atomic:
64
case
RegexNodeKind
.NegativeLookaround:
65
case
RegexNodeKind
.PositiveLookaround:
70
case
RegexNodeKind
.Capture:
75
case
RegexNodeKind
.Loop:
76
case
RegexNodeKind
.Lazyloop:
94
RegexNodeKind
.Atomic or
RegexNodeKind
.NegativeLookaround or
RegexNodeKind
.PositiveLookaround => true,
98
RegexNodeKind
.Alternate or
RegexNodeKind
.BackreferenceConditional or
RegexNodeKind
.ExpressionConditional => true,
101
RegexNodeKind
.Capture => true,
105
RegexNodeKind
.Concatenate => i == childCount - 1,
111
RegexNodeKind
.Loop or
RegexNodeKind
.Lazyloop when node.N == 1 => true,
System\Text\RegularExpressions\RegexWriter.cs (56)
14
private const
RegexNodeKind
BeforeChild = (
RegexNodeKind
)64;
15
private const
RegexNodeKind
AfterChild = (
RegexNodeKind
)128;
201
private void EmitFragment(
RegexNodeKind
nodeType, RegexNode node, int curIndex)
215
case
RegexNodeKind
.Concatenate | BeforeChild:
216
case
RegexNodeKind
.Concatenate | AfterChild:
217
case
RegexNodeKind
.Empty:
220
case
RegexNodeKind
.Alternate | BeforeChild:
228
case
RegexNodeKind
.Alternate | AfterChild:
247
case
RegexNodeKind
.BackreferenceConditional | BeforeChild:
260
case
RegexNodeKind
.BackreferenceConditional | AfterChild:
278
case
RegexNodeKind
.ExpressionConditional | BeforeChild:
290
case
RegexNodeKind
.ExpressionConditional | AfterChild:
311
case
RegexNodeKind
.Loop | BeforeChild:
312
case
RegexNodeKind
.Lazyloop | BeforeChild:
327
case
RegexNodeKind
.Loop | AfterChild:
328
case
RegexNodeKind
.Lazyloop | AfterChild:
331
int Lazy = (nodeType - (
RegexNodeKind
.Loop | AfterChild));
343
case
RegexNodeKind
.Capture | BeforeChild:
347
case
RegexNodeKind
.Capture | AfterChild:
351
case
RegexNodeKind
.PositiveLookaround | BeforeChild:
356
case
RegexNodeKind
.PositiveLookaround | AfterChild:
361
case
RegexNodeKind
.NegativeLookaround | BeforeChild:
367
case
RegexNodeKind
.NegativeLookaround | AfterChild:
373
case
RegexNodeKind
.Atomic | BeforeChild:
377
case
RegexNodeKind
.Atomic | AfterChild:
381
case
RegexNodeKind
.One:
382
case
RegexNodeKind
.Notone:
386
case
RegexNodeKind
.Notoneloop:
387
case
RegexNodeKind
.Notoneloopatomic:
388
case
RegexNodeKind
.Notonelazy:
389
case
RegexNodeKind
.Oneloop:
390
case
RegexNodeKind
.Oneloopatomic:
391
case
RegexNodeKind
.Onelazy:
394
Emit(((node.Kind is
RegexNodeKind
.Oneloop or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Onelazy) ?
403
case
RegexNodeKind
.Setloop:
404
case
RegexNodeKind
.Setloopatomic:
405
case
RegexNodeKind
.Setlazy:
419
case
RegexNodeKind
.Multi:
423
case
RegexNodeKind
.Set:
427
case
RegexNodeKind
.Backreference:
431
case
RegexNodeKind
.Nothing:
432
case
RegexNodeKind
.Bol:
433
case
RegexNodeKind
.Eol:
434
case
RegexNodeKind
.Boundary:
435
case
RegexNodeKind
.NonBoundary:
436
case
RegexNodeKind
.ECMABoundary:
437
case
RegexNodeKind
.NonECMABoundary:
438
case
RegexNodeKind
.Beginning:
439
case
RegexNodeKind
.Start:
440
case
RegexNodeKind
.EndZ:
441
case
RegexNodeKind
.End:
442
case
RegexNodeKind
.UpdateBumpalong:
System\Text\RegularExpressions\Symbolic\RegexNodeConverter.cs (49)
57
case
RegexNodeKind
.One:
61
case
RegexNodeKind
.Notone:
65
case
RegexNodeKind
.Set:
69
case
RegexNodeKind
.Multi:
84
case
RegexNodeKind
.Concatenate:
85
case
RegexNodeKind
.Alternate:
86
case
RegexNodeKind
.Loop:
87
case
RegexNodeKind
.Lazyloop:
88
case
RegexNodeKind
.Capture when node.N == -1: // N == -1 because balancing groups (which have N >= 0) aren't supported
106
case
RegexNodeKind
.Oneloop:
107
case
RegexNodeKind
.Onelazy:
108
case
RegexNodeKind
.Notoneloop:
109
case
RegexNodeKind
.Notonelazy:
117
result.AddLast(_builder.CreateLoop(_builder.CreateSingleton(bdd), node.Kind is
RegexNodeKind
.Onelazy or
RegexNodeKind
.Notonelazy, node.M, node.N));
121
case
RegexNodeKind
.Setloop:
122
case
RegexNodeKind
.Setlazy:
128
result.AddLast(_builder.CreateLoop(_builder.CreateSingleton(setBdd), node.Kind ==
RegexNodeKind
.Setlazy, node.M, node.N));
132
case
RegexNodeKind
.Empty:
133
case
RegexNodeKind
.UpdateBumpalong: // UpdateBumpalong is a directive relevant only to backtracking and can be ignored just like Empty
136
case
RegexNodeKind
.Nothing:
142
case
RegexNodeKind
.Beginning:
146
case
RegexNodeKind
.Bol:
151
case
RegexNodeKind
.End: // \z anchor
155
case
RegexNodeKind
.EndZ: // \Z anchor
160
case
RegexNodeKind
.Eol:
165
case
RegexNodeKind
.Boundary:
170
case
RegexNodeKind
.NonBoundary:
180
RegexNodeKind
.Atomic or
RegexNodeKind
.Setloopatomic or
RegexNodeKind
.Oneloopatomic or
RegexNodeKind
.Notoneloopatomic => SR.ExpressionDescription_AtomicSubexpressions,
181
RegexNodeKind
.Backreference => SR.ExpressionDescription_Backreference,
182
RegexNodeKind
.BackreferenceConditional => SR.ExpressionDescription_Conditional,
183
RegexNodeKind
.Capture => SR.ExpressionDescription_BalancingGroup,
184
RegexNodeKind
.ExpressionConditional => SR.ExpressionDescription_IfThenElse,
185
RegexNodeKind
.NegativeLookaround => SR.ExpressionDescription_NegativeLookaround,
186
RegexNodeKind
.PositiveLookaround => SR.ExpressionDescription_PositiveLookaround,
187
RegexNodeKind
.Start => SR.ExpressionDescription_ContiguousMatches,
195
string description = $"Unexpected ({nameof(
RegexNodeKind
)}: {node.Kind})";
211
case
RegexNodeKind
.Concatenate:
221
case
RegexNodeKind
.Alternate:
250
case
RegexNodeKind
.Loop:
251
case
RegexNodeKind
.Lazyloop:
260
result.AddLast(_builder.CreateLoop(body, node.Kind ==
RegexNodeKind
.Lazyloop, node.M, node.N));
267
Debug.Assert(node.Kind ==
RegexNodeKind
.Capture && node.N == -1);
285
Debug.Assert(rootResult.Count == 1 || root.Kind ==
RegexNodeKind
.Concatenate || root.Kind ==
RegexNodeKind
.Capture);
312
Debug.Assert(node.Kind ==
RegexNodeKind
.Set);
System\Text\RegularExpressions\Symbolic\SymbolicRegexKind.cs (16)
9
/// <summary>An empty node that matches a zero-width input (e.g. <see cref="
RegexNodeKind
.Empty"/>).</summary>
11
/// <summary>A node that matches a single character (i.e. <see cref="
RegexNodeKind
.One"/>, <see cref="
RegexNodeKind
.Notone"/>, or <see cref="
RegexNodeKind
.Set"/>).</summary>
13
/// <summary>A node that matches a sequence of nodes (i.e. <see cref="
RegexNodeKind
.Concatenate"/>).</summary>
15
/// <summary>A node that matches a loop (e.g. <see cref="
RegexNodeKind
.Loop"/>, <see cref="
RegexNodeKind
.Lazyloop"/>, <see cref="
RegexNodeKind
.Setloop"/>, etc.).</summary>
17
/// <summary>A node that matches if any of its nodes match and that matches them in a fixed order that mirrors how the backtracking engines operate (e.g. <see cref="
RegexNodeKind
.Alternate"/>).</summary>
20
/// <summary>A node that represents a beginning anchor (i.e. <see cref="
RegexNodeKind
.Beginning"/>).</summary>
22
/// <summary>A node that represents an ending anchor (i.e. <see cref="
RegexNodeKind
.End"/>).</summary>
24
/// <summary>A node that represents an ending \Z anchor (i.e. <see cref="
RegexNodeKind
.EndZ"/>).</summary>
28
/// <summary>A node that represents a beginning-of-line anchor (i.e. <see cref="
RegexNodeKind
.Bol"/>).</summary>
30
/// <summary>A node that represents a end-of-line anchor (i.e. <see cref="
RegexNodeKind
.Eol"/>).</summary>
32
/// <summary>A node that represents a word boundary anchor (i.e. <see cref="
RegexNodeKind
.Boundary"/>).</summary>
34
/// <summary>A node that represents a word non-boundary anchor (i.e. <see cref="
RegexNodeKind
.NonBoundary"/>).</summary>
System\Text\RegularExpressions\Symbolic\SymbolicRegexMatcher.cs (1)
211
findOptimizations.LeadingAnchor is not
RegexNodeKind
.Beginning)