90 instantiations of RegexNode
System.Text.RegularExpressions (90)
System\Text\RegularExpressions\RegexCompiler.cs (3)
2057
new
RegexNode
(RegexNodeKind.Empty, child.Options));
2097
new
(RegexNodeKind.One, multi.Options, multi.Str[1]) :
2098
new
(RegexNodeKind.Multi, multi.Options, multi.Str.Substring(1));
System\Text\RegularExpressions\RegexNode.cs (27)
95
new
RegexNode
(Kind, Options, Str!) :
96
new
RegexNode
(Kind, Options, Ch);
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);
207
RegexNode loopAsChild =
new
(RegexNodeKind.Loop, Options, M, N);
442
parent.InsertChild(1, new
RegexNode
(RegexNodeKind.UpdateBumpalong, node.Options));
548
var atomic = new
RegexNode
(RegexNodeKind.Atomic, existingChild.Options);
662
0 => new
RegexNode
(Kind == RegexNodeKind.Alternate ? RegexNodeKind.Nothing : RegexNodeKind.Empty, Options),
761
return new
RegexNode
(RegexNodeKind.Empty, child.Options);
951
return new
RegexNode
(RegexNodeKind.Nothing, Options);
990
u = u.M == 0 ? new
RegexNode
(RegexNodeKind.Empty, Options) : child;
1078
return new
RegexNode
(RegexNodeKind.Nothing, Options);
1300
var newAlternate = new
RegexNode
(RegexNodeKind.Alternate, alternation.Options);
1311
newAlternate.AddChild(new
RegexNode
(RegexNodeKind.Empty, children[i].Options));
1318
var atomic = new
RegexNode
(RegexNodeKind.Atomic, alternation.Options);
1325
var newConcat = new
RegexNode
(RegexNodeKind.Concatenate, alternation.Options);
1479
new
RegexNode
(RegexNodeKind.One, startingNodeOptions, startingSpan[0]) :
1480
new
RegexNode
(RegexNodeKind.Multi, startingNodeOptions, startingSpan.ToString());
1481
var newAlternate = new
RegexNode
(RegexNodeKind.Alternate, startingNodeOptions);
1525
var atomic = new
RegexNode
(RegexNodeKind.Atomic, startingNodeOptions);
1530
var newConcat = new
RegexNode
(RegexNodeKind.Concatenate, startingNodeOptions);
1748
return new
RegexNode
(RegexNodeKind.Empty, Options);
2350
AddChild(new
RegexNode
(RegexNodeKind.Empty, Options));
2368
AddChild(new
RegexNode
(RegexNodeKind.Empty, Options));
3291
return new
RegexNode
(RegexNodeKind.Empty, Options);
3319
var result = new
RegexNode
(lazy ? RegexNodeKind.Lazyloop : RegexNodeKind.Loop, Options, min, max);
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);
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);
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);
1097
return new
RegexNode
(nodeType, _options);
1161
new
RegexNode
(TypeFromCode(ch), _options);
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());
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);
2198
_concatenation!.AddChild(new
RegexNode
(RegexNodeKind.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch)));
2244
_alternation = new
RegexNode
(RegexNodeKind.Alternate, _options);
2245
_concatenation = new
RegexNode
(RegexNodeKind.Concatenate, _options);
2262
_concatenation = new
RegexNode
(RegexNodeKind.Concatenate, _options);
357 references to RegexNode
System.Text.RegularExpressions (357)
System\Text\RegularExpressions\RegexCompiler.cs (62)
1272
(
RegexNode
LoopNode, (char Char, string? String, StringComparison StringComparison, char[]? Chars) Literal) target = _regexTree.FindOptimizations.LiteralAfterLoop.Value;
1456
RegexNode
node = _regexTree.Root;
1671
void EmitAlternation(
RegexNode
node)
1890
bool TryEmitAlternationAsSwitch(
RegexNode
node, int childCount, bool isAtomic)
1930
void EmitSwitchedBranches(
RegexNode
node, int childCount, bool useILSwitch, int minValue, int range)
1946
RegexNode
child = node.Child(i);
1947
RegexNode
? startingLiteralNode = child.FindStartingLiteralNode(allowZeroWidth: false);
2026
RegexNode
child = node.Child(i);
2027
RegexNode
? startingLiteralNode = child.FindStartingLiteralNode(allowZeroWidth: false);
2053
RegexNode
originalFirst = child.Child(0);
2093
static
RegexNode
CreateSlicedMulti(
RegexNode
multi)
2103
void EmitBackreference(
RegexNode
node)
2293
void EmitBackreferenceConditional(
RegexNode
node)
2308
RegexNode
yesBranch = node.Child(0);
2309
RegexNode
? noBranch = node.Child(1) is { Kind: not RegexNodeKind.Empty } childNo ? childNo : null;
2452
void EmitExpressionConditional(
RegexNode
node)
2465
RegexNode
condition = node.Child(0);
2469
RegexNode
yesBranch = node.Child(1);
2470
RegexNode
? noBranch = node.Child(2) is { Kind: not RegexNodeKind.Empty } childNo ? childNo : null;
2645
void EmitCapture(
RegexNode
node,
RegexNode
? subsequent = null)
2664
RegexNode
child = node.Child(0);
2771
void EmitPositiveLookaroundAssertion(
RegexNode
node)
2815
void EmitNegativeLookaroundAssertion(
RegexNode
node)
2847
RegexNode
child = node.Child(0);
2932
void EmitNode(
RegexNode
node,
RegexNode
? subsequent = null, bool emitLengthChecksIfRequired = true)
3074
void EmitAtomic(
RegexNode
node,
RegexNode
? subsequent)
3079
RegexNode
child = node.Child(0);
3118
void EmitUpdateBumpalong(
RegexNode
node)
3138
void EmitConcatenation(
RegexNode
node,
RegexNode
? subsequent, bool emitLengthChecksIfRequired)
3192
static unsafe
RegexNode
? GetSubsequent(int index,
RegexNode
node,
RegexNode
? subsequent)
3197
RegexNode
next = node.Child(i);
3209
void EmitSingleChar(
RegexNode
node, bool emitLengthCheck = true, LocalBuilder? offset = null)
3284
void EmitBoundary(
RegexNode
node)
3344
void EmitAnchors(
RegexNode
node)
3482
void EmitMultiChar(
RegexNode
node, bool emitLengthCheck)
3534
void EmitSingleCharLoop(
RegexNode
node,
RegexNode
? subsequent = null, bool emitLengthChecksIfRequired = true)
3655
subsequent?.FindStartingLiteralNode() is
RegexNode
literal &&
3660
if (subsequent is not null &&
RegexNode
.CanReduceLoopBacktrackingToSinglePosition(node, subsequent))
3809
void EmitSingleCharLazy(
RegexNode
node,
RegexNode
? subsequent = null, bool emitLengthChecksIfRequired = true)
3913
subsequent?.FindStartingLiteral() is
RegexNode
.StartingLiteralData literal &&
4055
subsequent?.FindStartingLiteralNode() is
RegexNode
literal2 &&
4156
void EmitLazy(
RegexNode
node)
4163
RegexNode
child = node.Child(0);
4518
void EmitSingleCharRepeater(
RegexNode
node, bool emitLengthChecksIfRequired = true)
4536
case <=
RegexNode
.MultiVsRepeaterLimit when node.IsOneFamily:
4668
void EmitSingleCharAtomicLoop(
RegexNode
node)
4915
void EmitAtomicSingleCharZeroOrOne(
RegexNode
node)
5004
void EmitNonBacktrackingRepeater(
RegexNode
node)
5042
void EmitLoop(
RegexNode
node)
5048
RegexNode
child = node.Child(0);
5440
bool CanEmitIndexOf(
RegexNode
node, out int literalLength)
5473
void EmitIndexOf(
RegexNode
node, bool useLast, bool negate)
5665
RegexNode
root = _regexTree!.Root.Child(0);
System\Text\RegularExpressions\RegexFindOptimizations.cs (6)
18
public static RegexFindOptimizations Create(
RegexNode
root, RegexOptions options)
24
RegexPrefixAnalyzer.FindLeadingPositiveLookahead(root) is
RegexNode
positiveLookahead)
46
private unsafe RegexFindOptimizations(
RegexNode
root, RegexOptions options, bool isLeadingPartial)
202
(
RegexNode
LoopNode, (char Char, string? String, StringComparison StringComparison, char[]? Chars) Literal)? literalAfterLoop = RegexPrefixAnalyzer.FindLiteralFollowingLeadingLoop(root);
336
public (
RegexNode
LoopNode, (char Char, string? String, StringComparison StringComparison, char[]? Chars) Literal)? LiteralAfterLoop { get; }
820
(
RegexNode
loopNode, (char Char, string? String, StringComparison StringComparison, char[]? Chars) literal) = LiteralAfterLoop.GetValueOrDefault();
System\Text\RegularExpressions\RegexNode.cs (148)
19
/// <remarks>null if no children, a <see cref="
RegexNode
"/> if one child, or a <see cref="List{RegexNode}"/> if multiple children.</remarks>
49
public
RegexNode
? Parent;
87
public
RegexNode
CloneCharLoopWithOneLessIteration()
94
RegexNode
newNode = IsSetFamily ?
110
public static
RegexNode
CreateOneWithCaseConversion(char ch, RegexOptions options, CultureInfo? culture, ref RegexCaseBehavior caseBehavior)
135
public
RegexNode
ReverseConcatenationIfRightToLeft()
141
((List<
RegexNode
>)Children!).Reverse();
207
RegexNode
loopAsChild = new(RegexNodeKind.Loop, Options, M, N);
245
var toExamine = new Stack<
RegexNode
>();
249
RegexNode
node = toExamine.Pop();
255
RegexNode
child = node.Child(i);
369
internal
RegexNode
FinalOptimize()
371
RegexNode
rootNode = this;
423
RegexNode
node = rootNode.Child(0); // skip implicit root capture node
480
RegexNode
child = Child(i);
483
RegexNode
reduced = child.Reduce();
509
RegexNode
node = this;
544
RegexNode
existingChild = node.Child(node.ChildCount() - 1);
548
var
atomic = new RegexNode(RegexNodeKind.Atomic, existingChild.Options);
621
internal
RegexNode
Reduce()
657
private
RegexNode
ReplaceNodeIfUnnecessary()
674
private
RegexNode
ReduceGroup()
678
RegexNode
u = this;
695
private
RegexNode
ReduceAtomic()
707
RegexNode
atomic = this;
708
RegexNode
child = Child(0);
753
List<
RegexNode
>? branches = child.Children as List<
RegexNode
>;
794
RegexNode
startNode = branches[start];
830
RegexNode
nextChild = branches[next];
879
private
RegexNode
ReduceLoops()
883
RegexNode
u = this;
891
RegexNode
child = u.Child(0);
959
RegexNode
child = u.Child(0);
1010
private
RegexNode
ReduceSet()
1071
private
RegexNode
ReduceAlternation()
1085
RegexNode
node = ReplaceNodeIfUnnecessary();
1130
RegexNode
at;
1131
RegexNode
prev;
1133
List<
RegexNode
> children = (List<
RegexNode
>)Children!;
1145
if (at.Children is List<
RegexNode
> atChildren)
1155
RegexNode
atChild = (
RegexNode
)at.Children!;
1239
static
RegexNode
ExtractCommonPrefixNode(
RegexNode
alternation)
1242
Debug.Assert(alternation.Children is List<
RegexNode
> { Count: >= 2 });
1243
var children = (List<
RegexNode
>)alternation.Children;
1259
RegexNode
startingNode = children[startingIndex];
1260
RegexNode
required = startingNode.Kind == RegexNodeKind.Concatenate ? startingNode.Child(0) : startingNode;
1280
RegexNode
endingNode = children[endingIndex];
1281
RegexNode
other = endingNode.Kind == RegexNodeKind.Concatenate ? endingNode.Child(0) : endingNode;
1300
var
newAlternate = new RegexNode(RegexNodeKind.Alternate, alternation.Options);
1305
((List<
RegexNode
>)children[i].Children!).RemoveAt(0);
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);
1339
static
RegexNode
RemoveRedundantEmptiesAndNothings(
RegexNode
node)
1343
var children = (List<
RegexNode
>)node.Children!;
1349
RegexNode
child = children[i];
1382
static unsafe
RegexNode
ExtractCommonPrefixText(
RegexNode
alternation)
1385
Debug.Assert(alternation.Children is List<
RegexNode
> { Count: >= 2 });
1386
var children = (List<
RegexNode
>)alternation.Children;
1405
RegexNode
? startingNode = children[startingIndex].FindBranchOneOrMultiStart();
1478
var
prefix = startingSpan.Length == 1 ?
1481
var
newAlternate = new RegexNode(RegexNodeKind.Alternate, startingNodeOptions);
1484
RegexNode
branch = children[i];
1491
static void ProcessOneOrMulti(
RegexNode
node, ReadOnlySpan<char> startingSpan)
1523
if (alternation.Parent is
RegexNode
parent && parent.Kind == RegexNodeKind.Atomic)
1525
var
atomic = new RegexNode(RegexNodeKind.Atomic, startingNodeOptions);
1530
var
newConcat = new RegexNode(RegexNodeKind.Concatenate, startingNodeOptions);
1548
public
RegexNode
? FindBranchOneOrMultiStart()
1550
RegexNode
branch = Kind == RegexNodeKind.Concatenate ? Child(0) : this;
1587
if (Child(i).FindStartingLiteralNode(allowZeroWidth: false) is not
RegexNode
startingLiteralNode ||
1633
public
RegexNode
? FindStartingLiteralNode(bool allowZeroWidth = true)
1635
RegexNode
? node = this;
1673
if (FindStartingLiteralNode() is
RegexNode
node)
1740
private
RegexNode
ReduceConcatenation()
1757
RegexNode
child = Child(i);
1785
Debug.Assert(Children is List<
RegexNode
>);
1791
List<
RegexNode
> children = (List<
RegexNode
>)Children!;
1794
RegexNode
at = children[i];
1804
if (at.Children is List<
RegexNode
> atChildren)
1814
RegexNode
atChild = (
RegexNode
)at.Children!;
1832
RegexNode
prev = children[--j];
1868
Debug.Assert(Children is List<
RegexNode
>);
1870
var children = (List<
RegexNode
>)Children!;
1875
RegexNode
currentNode = children[current];
1876
RegexNode
nextNode = children[next];
2076
Debug.Assert(Children is List<
RegexNode
>);
2077
var children = (List<
RegexNode
>)Children;
2082
static void ProcessNode(
RegexNode
node,
RegexNode
subsequent)
2144
RegexNode
loopChild = node.Child(0);
2178
RegexNode
child = node.Child(0);
2188
RegexNode
child = node.Child(0);
2219
private
RegexNode
ReduceLookaround()
2238
static bool RemoveCaptures(
RegexNode
parent, int nodeIndex)
2240
RegexNode
node = parent.Child(nodeIndex);
2270
RegexNode
child = Child(0);
2309
private static bool? ContainsKind(
RegexNode
node, ReadOnlySpan<RegexNodeKind> kinds)
2339
private
RegexNode
ReduceBackreferenceConditional()
2357
private
RegexNode
ReduceExpressionConditional()
2376
RegexNode
condition = Child(0);
2400
internal static bool CanReduceLoopBacktrackingToSinglePosition(
RegexNode
loopNode,
RegexNode
subsequent)
2406
if (subsequent.FindStartingLiteralNode() is
RegexNode
literal)
2423
FindNextNodeInSequence(literal, out _) is
RegexNode
afterLiteral &&
2436
static bool CharInLoopSet(
RegexNode
loopNode, char ch) => loopNode.Kind switch
2453
private static bool CanBeMadeAtomic(
RegexNode
node,
RegexNode
subsequent, bool iterateNullableSubsequent, bool allowLazy)
2618
RegexNode
loopChild = node.Child(0);
2669
RegexNode
? nextSubsequent = FindNextNodeInSequence(subsequent, out bool reachedEnd);
2691
private static
RegexNode
? FindNextNodeInSequence(
RegexNode
node, out bool reachedEnd)
2700
RegexNode
? parent = node.Parent;
2710
var peers = (List<
RegexNode
>)parent.Children!;
2751
private static bool MayContainBacktracking(
RegexNode
node)
2787
RegexNode
node = this;
2794
node.Parent is not
RegexNode
parent)
2808
var peers = (List<
RegexNode
>)parent.Children!;
3116
RegexNode
child = Child(i);
3243
static bool CanJoinLengthCheck(
RegexNode
node) => node.Kind switch
3254
RegexNode
child = Child(childIndex);
3282
public
RegexNode
MakeQuantifier(bool lazy, int min, int max)
3319
var
result = new RegexNode(lazy ? RegexNodeKind.Lazyloop : RegexNodeKind.Loop, Options, min, max);
3325
public void AddChild(
RegexNode
newChild)
3335
else if (Children is
RegexNode
currentChild)
3337
Children = new List<
RegexNode
>() { currentChild, newChild };
3341
((List<
RegexNode
>)Children).Add(newChild);
3345
public void InsertChild(int index,
RegexNode
newChild)
3347
Debug.Assert(Children is List<
RegexNode
>);
3353
((List<
RegexNode
>)Children).Insert(index, newChild);
3356
public void ReplaceChild(int index,
RegexNode
newChild)
3369
private void UnsafeReplaceChild(int index,
RegexNode
newChild)
3373
if (Children is
RegexNode
)
3379
((List<
RegexNode
>)Children)[index] = newChild;
3383
public
RegexNode
Child(int i) => Children is
RegexNode
child ? child : ((List<
RegexNode
>)Children!)[i];
3392
if (Children is List<
RegexNode
> children)
3397
Debug.Assert(Children is
RegexNode
);
3428
static bool ExceedsMaxDepthAllowedDepth(
RegexNode
node, int allowedDepth)
3462
RegexNode
? curNode = this;
System\Text\RegularExpressions\RegexNodeKind.cs (42)
6
/// <summary>Specifies the kind of a <see cref="
RegexNode
"/>.</summary>
16
/// <remarks>The character is specified in <see cref="
RegexNode
.Ch"/>.</remarks>
19
/// <remarks>The character is specified in <see cref="
RegexNode
.Ch"/>.</remarks>
22
/// <remarks>The <see cref="RegexCharClass"/> set string is specified in <see cref="
RegexNode
.Str"/>.</remarks>
26
/// <remarks>The characters are specified in <see cref="
RegexNode
.Str"/>. This is purely a representational optimization, equivalent to multiple <see cref="One"/> nodes concatenated together.</remarks>
31
/// The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.
36
/// <remarks>The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.</remarks>
40
/// <remarks>The <see cref="RegexCharClass"/> set string is specified in <see cref="
RegexNode
.Str"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.</remarks>
45
/// <remarks>The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.</remarks>
49
/// <remarks>The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.</remarks>
53
/// <remarks>The <see cref="RegexCharClass"/> set string is specified in <see cref="
RegexNode
.Str"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.</remarks>
59
/// The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.
65
/// The character is specified in <see cref="
RegexNode
.Ch"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.
71
/// The <see cref="RegexCharClass"/> set string is specified in <see cref="
RegexNode
.Str"/>, the minimum number of iterations in <see cref="
RegexNode
.M"/>, and the maximum number of iterations in <see cref="
RegexNode
.N"/>.
77
/// <remarks>The capture group number referenced is stored in <see cref="
RegexNode
.M"/>.</remarks>
126
/// <summary>A loop around an arbitrary <see cref="
RegexNode
"/>, e.g. `(ab|cd)*`.</summary>
128
/// One and only one child, the expression in the loop. The minimum number of iterations is in <see cref="
RegexNode
.M"/>,
129
/// and the maximum number of iterations is in <see cref="
RegexNode
.N"/>.
132
/// <summary>A lazy loop around an arbitrary <see cref="
RegexNode
"/>, e.g. `(ab|cd)*?`.</summary>
134
/// One and only one child, the expression in the loop. The minimum number of iterations is in <see cref="
RegexNode
.M"/>,
135
/// and the maximum number of iterations is in <see cref="
RegexNode
.N"/>.
141
/// One and only one child, the expression in the capture. <see cref="
RegexNode
.M"/> is the number of the capture, and if a balancing
142
/// group, <see cref="
RegexNode
.N"/> is the uncapture.
169
/// The referenced capture group number is stored in <see cref="
RegexNode
.M"/>.
System\Text\RegularExpressions\RegexOpcode.cs (1)
151
/// For quantified constructs with a minimum of zero (<see cref="
RegexNode
.M"/> == 0), this opcode pushes a counter
System\Text\RegularExpressions\RegexParser.cs (41)
24
private
RegexNode
? _stack;
25
private
RegexNode
? _group;
26
private
RegexNode
? _alternation;
27
private
RegexNode
? _concatenation;
28
private
RegexNode
? _unit;
109
RegexNode
root = parser.ScanRegex();
144
RegexNode
root = parser.ScanReplacement();
270
private
RegexNode
ScanRegex()
332
_unit =
RegexNode
.CreateOneWithCaseConversion(_pattern[endpos - 1], _options, _culture, ref _caseBehavior);
353
if (ScanGroupOpen() is
RegexNode
grouper)
542
private
RegexNode
ScanReplacement()
818
private
RegexNode
? ScanGroupOpen()
1147
private
RegexNode
? ScanBackslash(bool scanOnly)
1216
RegexNode
? result = ScanBasicBackslash(scanOnly);
1226
private
RegexNode
? ScanBasicBackslash(bool scanOnly)
1355
RegexNode
.CreateOneWithCaseConversion(ch, _options, _culture, ref _caseBehavior) :
1360
private
RegexNode
ScanDollar()
1364
return
RegexNode
.CreateOneWithCaseConversion('$', _options, _culture, ref _caseBehavior);
1454
return
RegexNode
.CreateOneWithCaseConversion('$', _options, _culture, ref _caseBehavior);
1487
return
RegexNode
.CreateOneWithCaseConversion('$', _options, _culture, ref _caseBehavior);
1733
private
RegexNode
AnyNewLineCrLfGuardNode()
1741
var
lookbehindCr = new RegexNode(RegexNodeKind.PositiveLookaround, lookbehindOpts);
1745
var
crThenLf = new RegexNode(RegexNodeKind.Concatenate, lookaheadOpts);
1750
var
guard = new RegexNode(RegexNodeKind.NegativeLookaround, lookaheadOpts);
1762
private
RegexNode
AnyNewLineEndZNode()
1769
var
crlfEnd = new RegexNode(RegexNodeKind.Concatenate, lookaheadOpts);
1775
var
anyNewLineOptEnd = new RegexNode(RegexNodeKind.Concatenate, 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);
1799
private
RegexNode
AnyNewLineEolNode()
1806
var
innerAlt = new RegexNode(RegexNodeKind.Alternate, lookaheadOpts);
1809
var
lookahead = new RegexNode(RegexNodeKind.PositiveLookaround, lookaheadOpts);
1813
var
result = new RegexNode(RegexNodeKind.Concatenate, opts);
1825
private
RegexNode
AnyNewLineBolNode()
1832
var
innerAlt = new RegexNode(RegexNodeKind.Alternate, lookbehindOpts);
1835
var
lookbehind = new RegexNode(RegexNodeKind.PositiveLookaround, lookbehindOpts);
1839
var
result = new RegexNode(RegexNodeKind.Concatenate, opts);
2194
_concatenation!.AddChild(
RegexNode
.CreateOneWithCaseConversion(_pattern[pos], isReplacement ? _options & ~RegexOptions.IgnoreCase : _options, _culture, ref _caseBehavior));
2204
_concatenation!.AddChild(
RegexNode
.CreateOneWithCaseConversion(c, _options, _culture, ref _caseBehavior));
2241
private void StartGroup(
RegexNode
openGroup)
System\Text\RegularExpressions\RegexPrefixAnalyzer.cs (25)
21
public static string[]? FindPrefixes(
RegexNode
node, bool ignoreCase)
57
static unsafe bool FindPrefixesCore(
RegexNode
node, List<StringBuilder> results, bool ignoreCase)
340
public static unsafe string FindPrefix(
RegexNode
node)
348
static bool Process(
RegexNode
node, ref ValueStringBuilder vsb)
483
public static string? FindPrefixOrdinalCaseInsensitive(
RegexNode
node)
511
public static unsafe List<RegexFindOptimizations.FixedDistanceSet>? FindFixedDistanceSets(
RegexNode
root, bool thorough)
586
static bool TryFindRawFixedSets(
RegexNode
node, List<RegexFindOptimizations.FixedDistanceSet> results, ref int distance, bool thorough)
906
public static string? FindFirstCharClass(
RegexNode
root) => FindFirstOrLastCharClass(root, findFirst: true);
911
public static string? FindLastCharClass(
RegexNode
root) => FindFirstOrLastCharClass(root, findFirst: false);
913
public static string? FindFirstOrLastCharClass(
RegexNode
root, bool findFirst)
942
static bool? TryFindFirstOrLastCharClass(
RegexNode
node, bool findFirst, ref RegexCharClass? cc)
1127
public static unsafe (
RegexNode
LoopNode, (char Char, string? String, StringComparison StringComparison, char[]? Chars) Literal)? FindLiteralFollowingLeadingLoop(
RegexNode
node)
1154
RegexNode
firstChild = node.Child(0);
1166
RegexNode
nextChild = node.Child(1);
1256
public static
RegexNode
? FindLeadingPositiveLookahead(
RegexNode
node)
1258
RegexNode
? positiveLookahead = null;
1263
static bool FindLeadingPositiveLookahead(
RegexNode
node, ref
RegexNode
? positiveLookahead)
1330
public static RegexNodeKind FindLeadingAnchor(
RegexNode
node) =>
1334
public static RegexNodeKind FindTrailingAnchor(
RegexNode
node) =>
1338
private static RegexNodeKind FindLeadingOrTrailingAnchor(
RegexNode
node, bool leading)
1379
RegexNode
? child = null;
1385
RegexNode
tmpChild = node.Child(i);
System\Text\RegularExpressions\RegexReplacement.cs (2)
34
public unsafe RegexReplacement(string rep,
RegexNode
concat, Hashtable _caps)
46
RegexNode
child = concat.Child(i);
System\Text\RegularExpressions\RegexTree.cs (4)
11
/// Provides the core data describing a parsed <see cref="
RegexNode
"/> tree, along with necessary
18
/// <summary>The root node of the parsed <see cref="
RegexNode
"/> tree.</summary>
19
public readonly
RegexNode
Root;
43
internal RegexTree(
RegexNode
root, int captureCount, string[]? captureNames, Hashtable? captureNameToNumberMapping, Hashtable? captureNumberSparseMapping, RegexOptions options, CultureInfo? culture)
System\Text\RegularExpressions\RegexTreeAnalyzer.cs (14)
9
/// <summary>Analyzes a <see cref="RegexTree"/> of <see cref="
RegexNode
"/>s to produce data on the tree structure, in particular in support of code generation.</summary>
19
static bool TryAnalyze(
RegexNode
node, AnalysisResults results, bool isAtomicByAncestor, bool isInLoop)
33
(results._inLoops ??= new HashSet<
RegexNode
>()).Add(node);
49
(results._mayBacktrack ??= new HashSet<
RegexNode
>()).Add(node);
81
RegexNode
child = node.Child(i);
131
(results._mayBacktrack ??= new HashSet<
RegexNode
>()).Add(node);
154
internal readonly HashSet<
RegexNode
> _isAtomicByAncestor = new(); // since the root is implicitly atomic, every tree will contain atomic-by-ancestor nodes
156
internal readonly HashSet<
RegexNode
> _containsCapture = new(); // the root is a capture, so this will always contain at least the root node
158
internal HashSet<
RegexNode
>? _mayBacktrack;
160
internal HashSet<
RegexNode
>? _inLoops;
179
public bool IsAtomicByAncestor(
RegexNode
node) => _isAtomicByAncestor.Contains(node);
187
public bool MayContainCapture(
RegexNode
node) => !_complete || _containsCapture.Contains(node);
200
public bool MayBacktrack(
RegexNode
node) => !_complete || (_mayBacktrack?.Contains(node) ?? false);
220
public bool IsInLoop(
RegexNode
node) => !_complete || (_inLoops?.Contains(node) ?? false);
System\Text\RegularExpressions\RegexWriter.cs (2)
78
RegexNode
curNode = _tree.Root;
201
private void EmitFragment(RegexNodeKind nodeType,
RegexNode
node, int curIndex)
System\Text\RegularExpressions\Symbolic\DoublyLinkedList.cs (2)
14
/// <see cref="AddLast(DoublyLinkedList{T})"/> operation is made use of in the <see cref="RegexNodeConverter.ConvertToSymbolicRegexNode(
RegexNode
)"/> method
15
/// where it maintains linear construction time in terms of the overall number of AST nodes in a given <see cref="
RegexNode
"/> input.
System\Text\RegularExpressions\Symbolic\RegexNodeConverter.cs (8)
13
/// <summary>Provides functionality to convert <see cref="
RegexNode
"/>s to corresponding <see cref="SymbolicRegexNode{S}"/>s.</summary>
26
/// <summary>Converts the root <see cref="
RegexNode
"/> into its corresponding <see cref="SymbolicRegexNode{S}"/>.</summary>
29
internal SymbolicRegexNode<BDD> ConvertToSymbolicRegexNode(
RegexNode
root)
37
Stack<(
RegexNode
Node, DoublyLinkedList<SymbolicRegexNode<BDD>> Result, DoublyLinkedList<SymbolicRegexNode<BDD>>[]? ChildResults)> stack = new();
42
while (stack.TryPop(out (
RegexNode
Node, DoublyLinkedList<SymbolicRegexNode<BDD>> Result, DoublyLinkedList<SymbolicRegexNode<BDD>>[]? ChildResults) popped))
44
RegexNode
node = popped.Node;
191
static string UnexpectedNodeType(
RegexNode
node)
310
SymbolicRegexNode<BDD> ConvertSet(
RegexNode
node)