1031 references to RegexNodeKind
System.Text.RegularExpressions (1031)
System\Text\RegularExpressions\RegexCompiler.cs (6)
649case RegexNodeKind.Bol: 728case RegexNodeKind.End or RegexNodeKind.EndZ when _regexTree.FindOptimizations.MaxPossibleLength is int maxLength: 1249Debug.Assert(target.LoopNode.Kind is RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic);
System\Text\RegularExpressions\RegexFindOptimizations.cs (23)
27if (_rightToLeft && LeadingAnchor == RegexNodeKind.Bol) 30LeadingAnchor = RegexNodeKind.Unknown; 32if (LeadingAnchor is RegexNodeKind.Beginning or RegexNodeKind.Start or RegexNodeKind.EndZ or RegexNodeKind.End) 36(RegexNodeKind.Beginning, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_Beginning, 37(RegexNodeKind.Beginning, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_Beginning, 38(RegexNodeKind.Start, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_Start, 39(RegexNodeKind.Start, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_Start, 40(RegexNodeKind.End, false) => FindNextStartingPositionMode.LeadingAnchor_LeftToRight_End, 41(RegexNodeKind.End, true) => FindNextStartingPositionMode.LeadingAnchor_RightToLeft_End, 53if (TrailingAnchor is RegexNodeKind.End or RegexNodeKind.EndZ && 60FindMode = TrailingAnchor == RegexNodeKind.End ? 250LeadingAnchor == RegexNodeKind.Bol; // there's a leading BOL anchor we can otherwise search for 256public RegexNodeKind LeadingAnchor { get; } 259public RegexNodeKind TrailingAnchor { get; } 379Debug.Assert(LeadingAnchor != RegexNodeKind.Bol, "BOL isn't enabled for RTL"); 505if (LeadingAnchor == RegexNodeKind.Bol) 792Debug.Assert(loopNode.Kind is RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic);
System\Text\RegularExpressions\RegexNode.cs (611)
23public 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> 51public RegexNode(RegexNodeKind kind, RegexOptions options) 57public RegexNode(RegexNodeKind kind, RegexOptions options, char ch) 64public RegexNode(RegexNodeKind kind, RegexOptions options, string str) 71public RegexNode(RegexNodeKind kind, RegexOptions options, int m) 78public RegexNode(RegexNodeKind kind, RegexOptions options, int m, int n) 89Debug.Assert(Kind is RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or 90RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or 91RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic); 121return new RegexNode(RegexNodeKind.One, options & ~RegexOptions.IgnoreCase, ch); 127return new RegexNode(RegexNodeKind.Set, options & ~RegexOptions.IgnoreCase, stringSet); 131return new RegexNode(RegexNodeKind.One, options, ch); 138Kind == RegexNodeKind.Concatenate && 150private void MakeRep(RegexNodeKind kind, int min, int max) 152Kind += kind - RegexNodeKind.One; 161case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop: 164Kind += RegexNodeKind.Oneloopatomic - RegexNodeKind.Oneloop; 167case RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy: 171Kind += RegexNodeKind.Oneloopatomic - RegexNodeKind.Onelazy; 177Kind = RegexNodeKind.Empty; 181else if (Kind == RegexNodeKind.Oneloopatomic && N is >= 2 and <= MultiVsRepeaterLimit) 185Kind = RegexNodeKind.Multi; 203Debug.Assert(Kind == RegexNodeKind.Capture, "Every generated tree should begin with a capture node"); 222Debug.Assert(Kind != RegexNodeKind.Group, "All Group nodes should have been removed."); 227case RegexNodeKind.Group: 231case RegexNodeKind.Beginning: 232case RegexNodeKind.Bol: 233case RegexNodeKind.Boundary: 234case RegexNodeKind.ECMABoundary: 235case RegexNodeKind.Empty: 236case RegexNodeKind.End: 237case RegexNodeKind.EndZ: 238case RegexNodeKind.Eol: 239case RegexNodeKind.Multi: 240case RegexNodeKind.NonBoundary: 241case RegexNodeKind.NonECMABoundary: 242case RegexNodeKind.Nothing: 243case RegexNodeKind.Notone: 244case RegexNodeKind.Notonelazy: 245case RegexNodeKind.Notoneloop: 246case RegexNodeKind.Notoneloopatomic: 247case RegexNodeKind.One: 248case RegexNodeKind.Onelazy: 249case RegexNodeKind.Oneloop: 250case RegexNodeKind.Oneloopatomic: 251case RegexNodeKind.Backreference: 252case RegexNodeKind.Set: 253case RegexNodeKind.Setlazy: 254case RegexNodeKind.Setloop: 255case RegexNodeKind.Setloopatomic: 256case RegexNodeKind.Start: 257case RegexNodeKind.UpdateBumpalong: 261case RegexNodeKind.Atomic: 262case RegexNodeKind.Capture: 263case RegexNodeKind.Lazyloop: 264case RegexNodeKind.Loop: 265case RegexNodeKind.NegativeLookaround: 266case RegexNodeKind.PositiveLookaround: 270case RegexNodeKind.BackreferenceConditional: 274case RegexNodeKind.ExpressionConditional: 278case RegexNodeKind.Concatenate: 279case RegexNodeKind.Alternate: 291case RegexNodeKind.Multi: 296case RegexNodeKind.Set: 297case RegexNodeKind.Setloop: 298case RegexNodeKind.Setloopatomic: 299case RegexNodeKind.Setlazy: 311case RegexNodeKind.Backreference: 332Debug.Assert(rootNode.Kind == RegexNodeKind.Capture); 375case RegexNodeKind.Atomic: 379case RegexNodeKind.Concatenate: 384case RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when node.N == int.MaxValue: 385case RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy when node.N == int.MaxValue && !atomicByAncestry: 386if (node.Parent is { Kind: RegexNodeKind.Concatenate } parent) 388parent.InsertChild(1, new RegexNode(RegexNodeKind.UpdateBumpalong, node.Options)); 431case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop: 432case RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy: 438case RegexNodeKind.Atomic: 439case RegexNodeKind.PositiveLookaround: 440case RegexNodeKind.NegativeLookaround: 450case RegexNodeKind.Capture: 451case RegexNodeKind.Concatenate: 453if ((existingChild.Kind is RegexNodeKind.Alternate or RegexNodeKind.BackreferenceConditional or RegexNodeKind.ExpressionConditional or RegexNodeKind.Loop or RegexNodeKind.Lazyloop) && 454(node.Parent is null || node.Parent.Kind != RegexNodeKind.Atomic)) // validate grandparent isn't atomic 456var atomic = new RegexNode(RegexNodeKind.Atomic, existingChild.Options); 466case RegexNodeKind.Alternate: 467case RegexNodeKind.BackreferenceConditional: 468case RegexNodeKind.ExpressionConditional: 476if (node.Kind != RegexNodeKind.ExpressionConditional) // ReduceExpressionConditional will have already applied ending backtracking removal 491case RegexNodeKind.Lazyloop: 493goto case RegexNodeKind.Loop; 494case RegexNodeKind.Loop: 532case RegexNodeKind.Backreference: 539RegexNodeKind.Alternate => ReduceAlternation(), 540RegexNodeKind.Atomic => ReduceAtomic(), 541RegexNodeKind.Concatenate => ReduceConcatenation(), 542RegexNodeKind.Group => ReduceGroup(), 543RegexNodeKind.Loop or RegexNodeKind.Lazyloop => ReduceLoops(), 544RegexNodeKind.PositiveLookaround or RegexNodeKind.NegativeLookaround => ReduceLookaround(), 545RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy => ReduceSet(), 546RegexNodeKind.ExpressionConditional => ReduceExpressionConditional(), 547RegexNodeKind.BackreferenceConditional => ReduceBackreferenceConditional(), 560Debug.Assert(Kind is RegexNodeKind.Alternate or RegexNodeKind.Concatenate); 5630 => new RegexNode(Kind == RegexNodeKind.Alternate ? RegexNodeKind.Nothing : RegexNodeKind.Empty, Options), 577Debug.Assert(Kind == RegexNodeKind.Group); 580while (u.Kind == RegexNodeKind.Group) 605Debug.Assert(Kind == RegexNodeKind.Atomic); 610while (child.Kind == RegexNodeKind.Atomic) 620case RegexNodeKind.Empty: 621case RegexNodeKind.Nothing: 625case RegexNodeKind.Oneloopatomic: 626case RegexNodeKind.Notoneloopatomic: 627case RegexNodeKind.Setloopatomic: 632case RegexNodeKind.Oneloop: 633case RegexNodeKind.Notoneloop: 634case RegexNodeKind.Setloop: 635case RegexNodeKind.Onelazy: 636case RegexNodeKind.Notonelazy: 637case RegexNodeKind.Setlazy: 643case RegexNodeKind.Alternate: 652if (branches[0].Kind == RegexNodeKind.Empty) 654return new RegexNode(RegexNodeKind.Empty, child.Options); 663if (branches[i].Kind == RegexNodeKind.Empty) 767Debug.Assert(Kind is RegexNodeKind.Loop or RegexNodeKind.Lazyloop); 770RegexNodeKind kind = Kind; 783if (kind == RegexNodeKind.Loop) 787case RegexNodeKind.Oneloop: 788case RegexNodeKind.Oneloopatomic: 789case RegexNodeKind.Notoneloop: 790case RegexNodeKind.Notoneloopatomic: 791case RegexNodeKind.Setloop: 792case RegexNodeKind.Setloopatomic: 801case RegexNodeKind.Onelazy: 802case RegexNodeKind.Notonelazy: 803case RegexNodeKind.Setlazy: 837return new RegexNode(RegexNodeKind.Nothing, Options); 849case RegexNodeKind.One: 850case RegexNodeKind.Notone: 851case RegexNodeKind.Set: 852child.MakeRep(u.Kind == RegexNodeKind.Lazyloop ? RegexNodeKind.Onelazy : RegexNodeKind.Oneloop, u.M, u.N); 876Debug.Assert(Kind is RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy); 881Kind = RegexNodeKind.Nothing; 889Kind == RegexNodeKind.Set ? RegexNodeKind.One : 890Kind == RegexNodeKind.Setloop ? RegexNodeKind.Oneloop : 891Kind == RegexNodeKind.Setloopatomic ? RegexNodeKind.Oneloopatomic : 892RegexNodeKind.Onelazy; 899Kind == RegexNodeKind.Set ? RegexNodeKind.Notone : 900Kind == RegexNodeKind.Setloop ? RegexNodeKind.Notoneloop : 901Kind == RegexNodeKind.Setloopatomic ? RegexNodeKind.Notoneloopatomic : 902RegexNodeKind.Notonelazy; 925Debug.Assert(Kind == RegexNodeKind.Alternate); 930return new RegexNode(RegexNodeKind.Nothing, Options); 938if (node.Kind == RegexNodeKind.Alternate) 941if (node.Kind == RegexNodeKind.Alternate) 944if (node.Kind == RegexNodeKind.Alternate) 979if (at.Kind == RegexNodeKind.Alternate) 997else if (at.Kind is RegexNodeKind.Set or RegexNodeKind.One) 1002if (at.Kind == RegexNodeKind.Set) 1026if (prev.Kind == RegexNodeKind.One) 1036if (at.Kind == RegexNodeKind.One) 1046prev.Kind = RegexNodeKind.Set; 1053else if (at.Kind == RegexNodeKind.Nothing) 1077Debug.Assert(alternation.Kind == RegexNodeKind.Alternate); 1090if (child.Kind != RegexNodeKind.Concatenate || child.ChildCount() < 2) 1107case RegexNodeKind.One or RegexNodeKind.Notone or RegexNodeKind.Set: 1108case RegexNodeKind.Oneloopatomic or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Setloopatomic: 1109case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop or RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy when required.M == required.N: 1139var newAlternate = new RegexNode(RegexNodeKind.Alternate, alternation.Options); 1147if (alternation.Parent is RegexNode { Kind: RegexNodeKind.Atomic }) 1149var atomic = new RegexNode(RegexNodeKind.Atomic, alternation.Options); 1156var newConcat = new RegexNode(RegexNodeKind.Concatenate, alternation.Options); 1172Debug.Assert(node.Kind == RegexNodeKind.Alternate); 1183case RegexNodeKind.Empty when !seenEmpty: 1187case RegexNodeKind.Empty: 1188case RegexNodeKind.Nothing: 1215Debug.Assert(alternation.Kind == RegexNodeKind.Alternate); 1242if (startingNode.Kind == RegexNodeKind.One) 1262if (startingNode.Kind == RegexNodeKind.One) 1276Debug.Assert(startingNode.Kind == RegexNodeKind.Multi); 1307new RegexNode(RegexNodeKind.One, startingNodeOptions, startingSpan[0]) : 1308new RegexNode(RegexNodeKind.Multi, startingNodeOptions, startingSpan.ToString()); 1309var newAlternate = new RegexNode(RegexNodeKind.Alternate, startingNodeOptions); 1313ProcessOneOrMulti(branch.Kind == RegexNodeKind.Concatenate ? branch.Child(0) : branch, startingSpan); 1321if (node.Kind == RegexNodeKind.One) 1325node.Kind = RegexNodeKind.Empty; 1330Debug.Assert(node.Kind == RegexNodeKind.Multi); 1334node.Kind = RegexNodeKind.Empty; 1339node.Kind = RegexNodeKind.One; 1351if (alternation.Parent is RegexNode parent && parent.Kind == RegexNodeKind.Atomic) 1353var atomic = new RegexNode(RegexNodeKind.Atomic, startingNodeOptions); 1358var newConcat = new RegexNode(RegexNodeKind.Concatenate, startingNodeOptions); 1378RegexNode branch = Kind == RegexNodeKind.Concatenate ? Child(0) : this; 1379return branch.Kind is RegexNodeKind.One or RegexNodeKind.Multi ? branch : null; 1385Debug.Assert(Kind is RegexNodeKind.One or RegexNodeKind.Multi || (IsOneFamily && M > 0)); 1400case RegexNodeKind.One: 1401case RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy when node.M > 0: 1402case RegexNodeKind.Notone: 1403case RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Notonelazy when node.M > 0: 1404case RegexNodeKind.Set: 1405case RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy when node.M > 0: 1406case RegexNodeKind.Multi: 1409case RegexNodeKind.Atomic: 1410case RegexNodeKind.Concatenate: 1411case RegexNodeKind.Capture: 1412case RegexNodeKind.Group: 1413case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M > 0: 1414case RegexNodeKind.PositiveLookaround when allowZeroWidth: 1435case RegexNodeKind.One or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy: 1438case RegexNodeKind.Notone or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Notonelazy: 1441case RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy: 1457case RegexNodeKind.Multi: 1500Debug.Assert(Kind == RegexNodeKind.Concatenate); 1506return new RegexNode(RegexNodeKind.Empty, Options); 1516if (child.Kind == RegexNodeKind.Nothing) 1542Debug.Assert(Kind == RegexNodeKind.Concatenate); 1559if (at.Kind == RegexNodeKind.Concatenate && 1578else if (at.Kind is RegexNodeKind.Multi or RegexNodeKind.One) 1592if (prev.Kind == RegexNodeKind.One) 1594prev.Kind = RegexNodeKind.Multi; 1599((at.Kind == RegexNodeKind.One) ? $"{prev.Str}{at.Ch}" : prev.Str + at.Str) : 1600((at.Kind == RegexNodeKind.One) ? $"{at.Ch}{prev.Str}" : at.Str + prev.Str); 1602else if (at.Kind == RegexNodeKind.Empty) 1625Debug.Assert(Kind == RegexNodeKind.Concatenate); 1663case 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: 1664case RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy when nextNode.Kind == currentNode.Kind && currentNode.Str == nextNode.Str: 1666currentNode.Kind is RegexNodeKind.Oneloopatomic or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Setloopatomic) 1689case RegexNodeKind.Oneloop or RegexNodeKind.Onelazy when nextNode.Kind == RegexNodeKind.One && currentNode.Ch == nextNode.Ch: 1690case RegexNodeKind.Notoneloop or RegexNodeKind.Notonelazy when nextNode.Kind == RegexNodeKind.Notone && currentNode.Ch == nextNode.Ch: 1691case RegexNodeKind.Setloop or RegexNodeKind.Setlazy when nextNode.Kind == RegexNodeKind.Set && currentNode.Str == nextNode.Str: 1705case RegexNodeKind.Oneloop or RegexNodeKind.Onelazy when 1706nextNode.Kind == RegexNodeKind.Multi && 1739nextNode.Kind = RegexNodeKind.One; 1757case RegexNodeKind.One when (nextNode.Kind is RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy) && currentNode.Ch == nextNode.Ch: 1758case RegexNodeKind.Notone when (nextNode.Kind is RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Notonelazy) && currentNode.Ch == nextNode.Ch: 1759case RegexNodeKind.Set when (nextNode.Kind is RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy) && currentNode.Str == nextNode.Str: 1772case RegexNodeKind.Notone when nextNode.Kind == currentNode.Kind && currentNode.Ch == nextNode.Ch: 1773case RegexNodeKind.Set when nextNode.Kind == RegexNodeKind.Set && currentNode.Str == nextNode.Str: 1774currentNode.MakeRep(RegexNodeKind.Oneloop, 2, 2); 1823if (Kind is not RegexNodeKind.Concatenate) 1848if (node.Kind is RegexNodeKind.Capture or RegexNodeKind.Concatenate) 1858if (node.Kind == RegexNodeKind.Loop) 1875case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: true, allowLazy: false): 1884case RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy when CanBeMadeAtomic(node, subsequent, iterateNullableSubsequent: false, allowLazy: true): 1900node.Kind -= RegexNodeKind.Onelazy - RegexNodeKind.Oneloop; // lazy to greedy 1904case RegexNodeKind.Alternate or RegexNodeKind.BackreferenceConditional or RegexNodeKind.ExpressionConditional: 1915for (int b = node.Kind == RegexNodeKind.ExpressionConditional ? 1 : 0; b < alternateBranches; b++) 1935Debug.Assert(node.Kind is RegexNodeKind.Loop or RegexNodeKind.Lazyloop); 1941while (node.Kind == RegexNodeKind.Capture) 1952if (node.Kind == RegexNodeKind.Concatenate) 1969Debug.Assert(Kind is RegexNodeKind.PositiveLookaround or RegexNodeKind.NegativeLookaround); 1985if (Child(0).Kind == RegexNodeKind.Empty) 1987Kind = Kind == RegexNodeKind.PositiveLookaround ? RegexNodeKind.Empty : RegexNodeKind.Nothing; 1997Debug.Assert(Kind == RegexNodeKind.BackreferenceConditional); 2006AddChild(new RegexNode(RegexNodeKind.Empty, Options)); 2015Debug.Assert(Kind == RegexNodeKind.ExpressionConditional); 2024AddChild(new RegexNode(RegexNodeKind.Empty, Options)); 2033if (condition.Kind == RegexNodeKind.PositiveLookaround && (condition.Options & RegexOptions.RightToLeft) == 0) 2069Debug.Assert(subsequent.Kind != RegexNodeKind.Group); 2072case RegexNodeKind.Concatenate: 2073case RegexNodeKind.Capture: 2074case RegexNodeKind.Atomic: 2075case RegexNodeKind.PositiveLookaround when (subsequent.Options & RegexOptions.RightToLeft) == 0: // only lookaheads, not lookbehinds (represented as RTL PositiveLookaround nodes) 2076case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when subsequent.M > 0: 2099case RegexNodeKind.Alternate: 2100case RegexNodeKind.ExpressionConditional when childCount == 3: // condition, yes, and no branch 2116case RegexNodeKind.Oneloop: 2117case RegexNodeKind.Onelazy when allowLazy: 2120case RegexNodeKind.One when node.Ch != subsequent.Ch: 2121case RegexNodeKind.Notone when node.Ch == subsequent.Ch: 2122case RegexNodeKind.Set when !RegexCharClass.CharInClass(node.Ch, subsequent.Str!): 2123case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M > 0 && node.Ch != subsequent.Ch: 2124case RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch: 2125case RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!): 2126case RegexNodeKind.Multi when node.Ch != subsequent.Str![0]: 2127case RegexNodeKind.End: 2128case RegexNodeKind.EndZ or RegexNodeKind.Eol when node.Ch != '\n': 2131case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M == 0 && node.Ch != subsequent.Ch: 2132case RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch: 2133case RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(node.Ch, subsequent.Str!): 2134case RegexNodeKind.Boundary when node.M > 0 && RegexCharClass.IsBoundaryWordChar(node.Ch): 2135case RegexNodeKind.NonBoundary when node.M > 0 && !RegexCharClass.IsBoundaryWordChar(node.Ch): 2136case RegexNodeKind.ECMABoundary when node.M > 0 && RegexCharClass.IsECMAWordChar(node.Ch): 2137case RegexNodeKind.NonECMABoundary when node.M > 0 && !RegexCharClass.IsECMAWordChar(node.Ch): 2146case RegexNodeKind.Notoneloop: 2147case RegexNodeKind.Notonelazy when allowLazy: 2150case RegexNodeKind.One when node.Ch == subsequent.Ch: 2151case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M > 0 && node.Ch == subsequent.Ch: 2152case RegexNodeKind.Multi when node.Ch == subsequent.Str![0]: 2153case RegexNodeKind.End: 2156case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M == 0 && node.Ch == subsequent.Ch: 2165case RegexNodeKind.Setloop: 2166case RegexNodeKind.Setlazy when allowLazy: 2169case RegexNodeKind.One when !RegexCharClass.CharInClass(subsequent.Ch, node.Str!): 2170case RegexNodeKind.Set when !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!): 2171case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!): 2172case RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when subsequent.M > 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!): 2173case RegexNodeKind.Multi when !RegexCharClass.CharInClass(subsequent.Str![0], node.Str!): 2174case RegexNodeKind.End: 2175case RegexNodeKind.EndZ or RegexNodeKind.Eol when !RegexCharClass.CharInClass('\n', node.Str!): 2178case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when subsequent.M == 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!): 2179case RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when subsequent.M == 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!): 2180case RegexNodeKind.Boundary when node.M > 0 && node.Str is RegexCharClass.WordClass or RegexCharClass.DigitClass: 2181case RegexNodeKind.NonBoundary when node.M > 0 && node.Str is RegexCharClass.NotWordClass or RegexCharClass.NotDigitClass: 2182case RegexNodeKind.ECMABoundary when node.M > 0 && node.Str is RegexCharClass.ECMAWordClass or RegexCharClass.ECMADigitClass: 2183case RegexNodeKind.NonECMABoundary when node.M > 0 && node.Str is RegexCharClass.NotECMAWordClass or RegexCharClass.NotDigitClass: 2211case RegexNodeKind.Atomic: 2212case RegexNodeKind.Alternate: 2213case RegexNodeKind.Capture: 2217case RegexNodeKind.Concatenate: 2262case RegexNodeKind.One: 2263case RegexNodeKind.Notone: 2264case RegexNodeKind.Set: 2268case RegexNodeKind.Multi: 2272case RegexNodeKind.Notonelazy: 2273case RegexNodeKind.Notoneloop: 2274case RegexNodeKind.Notoneloopatomic: 2275case RegexNodeKind.Onelazy: 2276case RegexNodeKind.Oneloop: 2277case RegexNodeKind.Oneloopatomic: 2278case RegexNodeKind.Setlazy: 2279case RegexNodeKind.Setloop: 2280case RegexNodeKind.Setloopatomic: 2284case RegexNodeKind.Lazyloop: 2285case RegexNodeKind.Loop: 2289case RegexNodeKind.Alternate: 2302case RegexNodeKind.BackreferenceConditional: 2306case RegexNodeKind.ExpressionConditional: 2310case RegexNodeKind.Concatenate: 2322case RegexNodeKind.Atomic: 2323case RegexNodeKind.Capture: 2324case RegexNodeKind.Group: 2329case RegexNodeKind.Empty: 2330case RegexNodeKind.Nothing: 2331case RegexNodeKind.UpdateBumpalong: 2335case RegexNodeKind.Beginning: 2336case RegexNodeKind.Bol: 2337case RegexNodeKind.Boundary: 2338case RegexNodeKind.ECMABoundary: 2339case RegexNodeKind.End: 2340case RegexNodeKind.EndZ: 2341case RegexNodeKind.Eol: 2342case RegexNodeKind.NonBoundary: 2343case RegexNodeKind.NonECMABoundary: 2344case RegexNodeKind.Start: 2345case RegexNodeKind.NegativeLookaround: 2346case RegexNodeKind.PositiveLookaround: 2348case RegexNodeKind.Backreference: 2356goto case RegexNodeKind.Empty; 2375case RegexNodeKind.One: 2376case RegexNodeKind.Notone: 2377case RegexNodeKind.Set: 2381case RegexNodeKind.Multi: 2385case RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or 2386RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or 2387RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic: 2391case RegexNodeKind.Loop or RegexNodeKind.Lazyloop: 2406case RegexNodeKind.Alternate: 2429case RegexNodeKind.BackreferenceConditional: 2430case RegexNodeKind.ExpressionConditional: 2433int i = Kind == RegexNodeKind.BackreferenceConditional ? 0 : 1; 2439case RegexNodeKind.Concatenate: 2461case RegexNodeKind.Atomic: 2462case RegexNodeKind.Capture: 2467case RegexNodeKind.Empty: 2468case RegexNodeKind.Nothing: 2469case RegexNodeKind.UpdateBumpalong: 2470case RegexNodeKind.Beginning: 2471case RegexNodeKind.Bol: 2472case RegexNodeKind.Boundary: 2473case RegexNodeKind.ECMABoundary: 2474case RegexNodeKind.End: 2475case RegexNodeKind.EndZ: 2476case RegexNodeKind.Eol: 2477case RegexNodeKind.NonBoundary: 2478case RegexNodeKind.NonECMABoundary: 2479case RegexNodeKind.Start: 2480case RegexNodeKind.PositiveLookaround: 2481case RegexNodeKind.NegativeLookaround: 2485case RegexNodeKind.Backreference: 2493goto case RegexNodeKind.Empty; 2516Debug.Assert(Kind == RegexNodeKind.Concatenate, $"Expected Concatenate, got {Kind}"); 2529if (child.Kind is RegexNodeKind.One) 2542else if (child.Kind is RegexNodeKind.Multi) 2554else if (child.Kind is RegexNodeKind.Set || 2555(child.Kind is RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic && child.M == child.N)) 2564vsb.Append((char)(twoChars[0] | 0x20), child.Kind is RegexNodeKind.Set ? 1 : child.M); 2566else if (child.Kind is RegexNodeKind.Empty) 2573child.Kind is RegexNodeKind.Beginning or 2574RegexNodeKind.Bol or 2575RegexNodeKind.Start or 2577RegexNodeKind.Boundary or 2578RegexNodeKind.ECMABoundary or 2579RegexNodeKind.NonBoundary or 2580RegexNodeKind.NonECMABoundary or 2582RegexNodeKind.NegativeLookaround or 2583RegexNodeKind.PositiveLookaround or 2585RegexNodeKind.UpdateBumpalong) 2632Debug.Assert(Kind == RegexNodeKind.Concatenate, $"Expected Concatenate, got {Kind}"); 2636RegexNodeKind.One or RegexNodeKind.Notone or RegexNodeKind.Set => true, 2637RegexNodeKind.Multi => true, 2638RegexNodeKind.Oneloop or RegexNodeKind.Onelazy or RegexNodeKind.Oneloopatomic or 2639RegexNodeKind.Notoneloop or RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloopatomic or 2640RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic 2682return new RegexNode(RegexNodeKind.Empty, Options); 2688case <= MultiVsRepeaterLimit when Kind == RegexNodeKind.One: 2694Kind = RegexNodeKind.Multi; 2703case RegexNodeKind.One: 2704case RegexNodeKind.Notone: 2705case RegexNodeKind.Set: 2706MakeRep(lazy ? RegexNodeKind.Onelazy : RegexNodeKind.Oneloop, min, max); 2710var result = new RegexNode(lazy ? RegexNodeKind.Lazyloop : RegexNodeKind.Loop, Options, min, max); 2833public bool IsSetFamily => Kind is RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy; 2836public bool IsOneFamily => Kind is RegexNodeKind.One or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy; 2839public bool IsNotoneFamily => Kind is RegexNodeKind.Notone or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Notonelazy; 2890case RegexNodeKind.Oneloop: 2891case RegexNodeKind.Oneloopatomic: 2892case RegexNodeKind.Notoneloop: 2893case RegexNodeKind.Notoneloopatomic: 2894case RegexNodeKind.Onelazy: 2895case RegexNodeKind.Notonelazy: 2896case RegexNodeKind.One: 2897case RegexNodeKind.Notone: 2900case RegexNodeKind.Capture: 2907case RegexNodeKind.Backreference: 2908case RegexNodeKind.BackreferenceConditional: 2911case RegexNodeKind.Multi: 2919case RegexNodeKind.Set: 2920case RegexNodeKind.Setloop: 2921case RegexNodeKind.Setloopatomic: 2922case RegexNodeKind.Setlazy: 2929case RegexNodeKind.Oneloop: 2930case RegexNodeKind.Oneloopatomic: 2931case RegexNodeKind.Notoneloop: 2932case RegexNodeKind.Notoneloopatomic: 2933case RegexNodeKind.Onelazy: 2934case RegexNodeKind.Notonelazy: 2935case RegexNodeKind.Setloop: 2936case RegexNodeKind.Setloopatomic: 2937case RegexNodeKind.Setlazy: 2938case RegexNodeKind.Loop: 2939case RegexNodeKind.Lazyloop:
System\Text\RegularExpressions\RegexParser.cs (60)
277StartGroup(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); 403new RegexNode(RegexNodeKind.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.AnyClass) : 404new RegexNode(RegexNodeKind.Notone, _options & ~RegexOptions.IgnoreCase, '\n'); 521_concatenation = new RegexNode(RegexNodeKind.Concatenate, _options); 759return new RegexNode(RegexNodeKind.Group, _options); 763return new RegexNode(RegexNodeKind.Capture, _options, _autocap++, -1); 776RegexNodeKind nodeType; 783nodeType = RegexNodeKind.Group; 789nodeType = RegexNodeKind.PositiveLookaround; 795nodeType = RegexNodeKind.NegativeLookaround; 800nodeType = RegexNodeKind.Atomic; 823nodeType = RegexNodeKind.PositiveLookaround; 834nodeType = RegexNodeKind.NegativeLookaround; 937return new RegexNode(RegexNodeKind.Capture, _options, capnum, uncapnum); 959return new RegexNode(RegexNodeKind.BackreferenceConditional, _options, capnum); 973return new RegexNode(RegexNodeKind.BackreferenceConditional, _options, tmpCapnum); 978nodeType = RegexNodeKind.ExpressionConditional; 1002nodeType = RegexNodeKind.Group; 1004if (_group!.Kind != RegexNodeKind.ExpressionConditional) 1096new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMAWordClass : RegexCharClass.WordClass); 1101new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMAWordClass : RegexCharClass.NotWordClass); 1106new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMASpaceClass : RegexCharClass.SpaceClass); 1111new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMASpaceClass : RegexCharClass.NotSpaceClass); 1116new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMADigitClass : RegexCharClass.DigitClass); 1121new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMADigitClass : RegexCharClass.NotDigitClass); 1138return new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), cc.ToStringClass()); 1142if (result != null && result.Kind == RegexNodeKind.Backreference && (result.Options & RegexOptions.IgnoreCase) != 0) 1203IsCaptureSlot(capnum) ? new RegexNode(RegexNodeKind.Backreference, _options, capnum) : 1235return scanOnly ? null : new RegexNode(RegexNodeKind.Backreference, _options, capnum); 1249return new RegexNode(RegexNodeKind.Backreference, _options, capnum); 1269_capnames?[capname] is int tmpCapnum ? new RegexNode(RegexNodeKind.Backreference, _options, tmpCapnum) : 1345return new RegexNode(RegexNodeKind.Backreference, _options, capnum); 1355return new RegexNode(RegexNodeKind.Backreference, _options, capnum); 1367return new RegexNode(RegexNodeKind.Backreference, _options, tmpCapnum); 1405return new RegexNode(RegexNodeKind.Backreference, _options, capnum); 1653private 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, 2022_concatenation!.AddChild(new RegexNode(RegexNodeKind.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch))); 2052if (_group.Kind == RegexNodeKind.ExpressionConditional && _group.ChildCount() == 0) 2068_alternation = new RegexNode(RegexNodeKind.Alternate, _options); 2069_concatenation = new RegexNode(RegexNodeKind.Concatenate, _options); 2077if (_group!.Kind is RegexNodeKind.ExpressionConditional or RegexNodeKind.BackreferenceConditional) 2086_concatenation = new RegexNode(RegexNodeKind.Concatenate, _options); 2092if (_group!.Kind is RegexNodeKind.ExpressionConditional or RegexNodeKind.BackreferenceConditional) 2096if (_group.Kind == RegexNodeKind.BackreferenceConditional && _group.ChildCount() > 2 || _group.ChildCount() > 3)
System\Text\RegularExpressions\RegexPrefixAnalyzer.cs (180)
84case RegexNodeKind.Atomic: 85case RegexNodeKind.Capture: 90case RegexNodeKind.Bol: 91case RegexNodeKind.Eol: 92case RegexNodeKind.Boundary: 93case RegexNodeKind.ECMABoundary: 94case RegexNodeKind.NonBoundary: 95case RegexNodeKind.NonECMABoundary: 96case RegexNodeKind.Beginning: 97case RegexNodeKind.Start: 98case RegexNodeKind.EndZ: 99case RegexNodeKind.End: 100case RegexNodeKind.Empty: 101case RegexNodeKind.UpdateBumpalong: 102case RegexNodeKind.PositiveLookaround: 103case RegexNodeKind.NegativeLookaround: 112case RegexNodeKind.One or RegexNodeKind.Oneloop or RegexNodeKind.Onelazy or RegexNodeKind.Oneloopatomic when !ignoreCase || !RegexCharClass.ParticipatesInCaseConversion(node.Ch): 114int reps = node.Kind is RegexNodeKind.One ? 1 : Math.Min(node.M, MaxPrefixLength); 119return node.Kind is RegexNodeKind.One || reps == node.N; 124case RegexNodeKind.Multi: 156case RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic when !RegexCharClass.IsNegated(node.Str!): // negated sets are too complex to analyze 164int reps = node.Kind is RegexNodeKind.Set ? 1 : Math.Min(node.M, MaxPrefixLength); 209return node.Kind is RegexNodeKind.Set || reps == node.N; 212case RegexNodeKind.Concatenate: 226case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M > 0: 242case RegexNodeKind.Alternate: 363case RegexNodeKind.Concatenate: 377case RegexNodeKind.Alternate when !rtl: // for RTL we'd need to be matching the suffixes of the alternation cases 422case RegexNodeKind.One: 427case RegexNodeKind.Multi: 432case RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy when node.M > 0: 439case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M > 0: 454case RegexNodeKind.Atomic: 455case RegexNodeKind.Capture: 459case RegexNodeKind.Bol: 460case RegexNodeKind.Eol: 461case RegexNodeKind.Boundary: 462case RegexNodeKind.ECMABoundary: 463case RegexNodeKind.NonBoundary: 464case RegexNodeKind.NonECMABoundary: 465case RegexNodeKind.Beginning: 466case RegexNodeKind.Start: 467case RegexNodeKind.EndZ: 468case RegexNodeKind.End: 469case RegexNodeKind.Empty: 470case RegexNodeKind.UpdateBumpalong: 471case RegexNodeKind.PositiveLookaround: 472case RegexNodeKind.NegativeLookaround: 491case RegexNodeKind.Atomic: 492case RegexNodeKind.Capture: 493case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M > 0: 497case RegexNodeKind.Concatenate: 600case RegexNodeKind.One: 609case RegexNodeKind.Onelazy or RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic when node.M > 0: 621case RegexNodeKind.Multi: 633case RegexNodeKind.Set: 641case RegexNodeKind.Setlazy or RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic when node.M > 0: 652case RegexNodeKind.Notone: 658case RegexNodeKind.Notonelazy or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic when node.M == node.N: 662case RegexNodeKind.Beginning: 663case RegexNodeKind.Bol: 664case RegexNodeKind.Boundary: 665case RegexNodeKind.ECMABoundary: 666case RegexNodeKind.Empty: 667case RegexNodeKind.End: 668case RegexNodeKind.EndZ: 669case RegexNodeKind.Eol: 670case RegexNodeKind.NonBoundary: 671case RegexNodeKind.NonECMABoundary: 672case RegexNodeKind.UpdateBumpalong: 673case RegexNodeKind.Start: 674case RegexNodeKind.NegativeLookaround: 675case RegexNodeKind.PositiveLookaround: 681case RegexNodeKind.Atomic: 682case RegexNodeKind.Group: 683case RegexNodeKind.Capture: 686case RegexNodeKind.Lazyloop or RegexNodeKind.Loop when node.M > 0: 696case RegexNodeKind.Concatenate: 709case RegexNodeKind.Alternate when thorough: 945case RegexNodeKind.One or RegexNodeKind.Oneloop or RegexNodeKind.Onelazy or RegexNodeKind.Oneloopatomic: 950return node.Kind is RegexNodeKind.One || node.M > 0 ? true : null; 954case RegexNodeKind.Notone or RegexNodeKind.Notoneloop or RegexNodeKind.Notoneloopatomic or RegexNodeKind.Notonelazy: 968return node.Kind is RegexNodeKind.Notone || node.M > 0 ? true : null; 972case RegexNodeKind.Set or RegexNodeKind.Setloop or RegexNodeKind.Setlazy or RegexNodeKind.Setloopatomic: 987node.Kind is RegexNodeKind.Set || node.M > 0 ? true : 991case RegexNodeKind.Multi: 1002case RegexNodeKind.Empty: 1003case RegexNodeKind.Nothing: 1004case RegexNodeKind.Bol: 1005case RegexNodeKind.Eol: 1006case RegexNodeKind.Boundary: 1007case RegexNodeKind.NonBoundary: 1008case RegexNodeKind.ECMABoundary: 1009case RegexNodeKind.NonECMABoundary: 1010case RegexNodeKind.Beginning: 1011case RegexNodeKind.Start: 1012case RegexNodeKind.EndZ: 1013case RegexNodeKind.End: 1014case RegexNodeKind.UpdateBumpalong: 1015case RegexNodeKind.PositiveLookaround: 1016case RegexNodeKind.NegativeLookaround: 1020case RegexNodeKind.Atomic: 1021case RegexNodeKind.Capture: 1027case RegexNodeKind.Loop: 1028case RegexNodeKind.Lazyloop: 1040case RegexNodeKind.Concatenate: 1057case RegexNodeKind.Alternate: 1078case RegexNodeKind.BackreferenceConditional: 1079case RegexNodeKind.ExpressionConditional: 1080int branchStart = node.Kind is RegexNodeKind.BackreferenceConditional ? 0 : 1; 1089case RegexNodeKind.Backreference: 1114while (node.Kind is RegexNodeKind.Atomic or RegexNodeKind.Capture) 1118if (node.Kind != RegexNodeKind.Concatenate) 1131while (firstChild.Kind is RegexNodeKind.Atomic or RegexNodeKind.Capture) 1135if (firstChild.Kind is not (RegexNodeKind.Setloop or RegexNodeKind.Setloopatomic or RegexNodeKind.Setlazy) || firstChild.N != int.MaxValue) 1143if (nextChild.Kind == RegexNodeKind.UpdateBumpalong) 1200while ((nextChild.Kind is RegexNodeKind.Atomic or RegexNodeKind.Capture or RegexNodeKind.Concatenate) || 1201(nextChild.Kind is RegexNodeKind.Loop or RegexNodeKind.Lazyloop && nextChild.M >= 1)) 1209(nextChild.Kind is RegexNodeKind.Set || nextChild.M >= 1)) 1232public static RegexNodeKind FindLeadingAnchor(RegexNode node) => 1236public static RegexNodeKind FindTrailingAnchor(RegexNode node) => 1240private static RegexNodeKind FindLeadingOrTrailingAnchor(RegexNode node, bool leading) 1246return RegexNodeKind.Unknown; 1253case RegexNodeKind.Bol: 1254case RegexNodeKind.Eol: 1255case RegexNodeKind.Beginning: 1256case RegexNodeKind.Start: 1257case RegexNodeKind.EndZ: 1258case RegexNodeKind.End: 1259case RegexNodeKind.Boundary: 1260case RegexNodeKind.ECMABoundary: 1264case RegexNodeKind.Atomic: 1265case RegexNodeKind.Capture: 1270case RegexNodeKind.Concatenate: 1281if (node.Child(i).Kind is not (RegexNodeKind.Empty or RegexNodeKind.PositiveLookaround or RegexNodeKind.NegativeLookaround)) 1292if (node.Child(i).Kind is not (RegexNodeKind.Empty or RegexNodeKind.PositiveLookaround or RegexNodeKind.NegativeLookaround)) 1309case RegexNodeKind.Alternate: 1313RegexNodeKind anchor = FindLeadingOrTrailingAnchor(node.Child(0), leading); 1314if (anchor == RegexNodeKind.Unknown) 1316return RegexNodeKind.Unknown; 1326return RegexNodeKind.Unknown; 1336return RegexNodeKind.Unknown;
System\Text\RegularExpressions\RegexReplacement.cs (4)
36Debug.Assert(concat.Kind == RegexNodeKind.Concatenate, $"Expected Concatenate, got {concat.Kind}"); 50case RegexNodeKind.Multi: 54case RegexNodeKind.One: 58case RegexNodeKind.Backreference:
System\Text\RegularExpressions\RegexTreeAnalyzer.cs (25)
49case RegexNodeKind.Alternate: 50case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M != node.N: 51case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop or RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy when node.M != node.N: 63case RegexNodeKind.Atomic: 64case RegexNodeKind.NegativeLookaround: 65case RegexNodeKind.PositiveLookaround: 70case RegexNodeKind.Capture: 75case RegexNodeKind.Loop: 76case RegexNodeKind.Lazyloop: 94RegexNodeKind.Atomic or RegexNodeKind.NegativeLookaround or RegexNodeKind.PositiveLookaround => true, 98RegexNodeKind.Alternate or RegexNodeKind.BackreferenceConditional or RegexNodeKind.ExpressionConditional => true, 101RegexNodeKind.Capture => true, 105RegexNodeKind.Concatenate => i == childCount - 1, 111RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.N == 1 => true,
System\Text\RegularExpressions\RegexWriter.cs (56)
14private const RegexNodeKind BeforeChild = (RegexNodeKind)64; 15private const RegexNodeKind AfterChild = (RegexNodeKind)128; 201private void EmitFragment(RegexNodeKind nodeType, RegexNode node, int curIndex) 215case RegexNodeKind.Concatenate | BeforeChild: 216case RegexNodeKind.Concatenate | AfterChild: 217case RegexNodeKind.Empty: 220case RegexNodeKind.Alternate | BeforeChild: 228case RegexNodeKind.Alternate | AfterChild: 247case RegexNodeKind.BackreferenceConditional | BeforeChild: 260case RegexNodeKind.BackreferenceConditional | AfterChild: 278case RegexNodeKind.ExpressionConditional | BeforeChild: 290case RegexNodeKind.ExpressionConditional | AfterChild: 311case RegexNodeKind.Loop | BeforeChild: 312case RegexNodeKind.Lazyloop | BeforeChild: 327case RegexNodeKind.Loop | AfterChild: 328case RegexNodeKind.Lazyloop | AfterChild: 331int Lazy = (nodeType - (RegexNodeKind.Loop | AfterChild)); 343case RegexNodeKind.Capture | BeforeChild: 347case RegexNodeKind.Capture | AfterChild: 351case RegexNodeKind.PositiveLookaround | BeforeChild: 356case RegexNodeKind.PositiveLookaround | AfterChild: 361case RegexNodeKind.NegativeLookaround | BeforeChild: 367case RegexNodeKind.NegativeLookaround | AfterChild: 373case RegexNodeKind.Atomic | BeforeChild: 377case RegexNodeKind.Atomic | AfterChild: 381case RegexNodeKind.One: 382case RegexNodeKind.Notone: 386case RegexNodeKind.Notoneloop: 387case RegexNodeKind.Notoneloopatomic: 388case RegexNodeKind.Notonelazy: 389case RegexNodeKind.Oneloop: 390case RegexNodeKind.Oneloopatomic: 391case RegexNodeKind.Onelazy: 394Emit(((node.Kind is RegexNodeKind.Oneloop or RegexNodeKind.Oneloopatomic or RegexNodeKind.Onelazy) ? 403case RegexNodeKind.Setloop: 404case RegexNodeKind.Setloopatomic: 405case RegexNodeKind.Setlazy: 419case RegexNodeKind.Multi: 423case RegexNodeKind.Set: 427case RegexNodeKind.Backreference: 431case RegexNodeKind.Nothing: 432case RegexNodeKind.Bol: 433case RegexNodeKind.Eol: 434case RegexNodeKind.Boundary: 435case RegexNodeKind.NonBoundary: 436case RegexNodeKind.ECMABoundary: 437case RegexNodeKind.NonECMABoundary: 438case RegexNodeKind.Beginning: 439case RegexNodeKind.Start: 440case RegexNodeKind.EndZ: 441case RegexNodeKind.End: 442case RegexNodeKind.UpdateBumpalong:
System\Text\RegularExpressions\Symbolic\RegexNodeConverter.cs (49)
57case RegexNodeKind.One: 61case RegexNodeKind.Notone: 65case RegexNodeKind.Set: 69case RegexNodeKind.Multi: 84case RegexNodeKind.Concatenate: 85case RegexNodeKind.Alternate: 86case RegexNodeKind.Loop: 87case RegexNodeKind.Lazyloop: 88case RegexNodeKind.Capture when node.N == -1: // N == -1 because balancing groups (which have N >= 0) aren't supported 106case RegexNodeKind.Oneloop: 107case RegexNodeKind.Onelazy: 108case RegexNodeKind.Notoneloop: 109case RegexNodeKind.Notonelazy: 117result.AddLast(_builder.CreateLoop(_builder.CreateSingleton(bdd), node.Kind is RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy, node.M, node.N)); 121case RegexNodeKind.Setloop: 122case RegexNodeKind.Setlazy: 128result.AddLast(_builder.CreateLoop(_builder.CreateSingleton(setBdd), node.Kind == RegexNodeKind.Setlazy, node.M, node.N)); 132case RegexNodeKind.Empty: 133case RegexNodeKind.UpdateBumpalong: // UpdateBumpalong is a directive relevant only to backtracking and can be ignored just like Empty 136case RegexNodeKind.Nothing: 142case RegexNodeKind.Beginning: 146case RegexNodeKind.Bol: 151case RegexNodeKind.End: // \z anchor 155case RegexNodeKind.EndZ: // \Z anchor 160case RegexNodeKind.Eol: 165case RegexNodeKind.Boundary: 170case RegexNodeKind.NonBoundary: 180RegexNodeKind.Atomic or RegexNodeKind.Setloopatomic or RegexNodeKind.Oneloopatomic or RegexNodeKind.Notoneloopatomic => SR.ExpressionDescription_AtomicSubexpressions, 181RegexNodeKind.Backreference => SR.ExpressionDescription_Backreference, 182RegexNodeKind.BackreferenceConditional => SR.ExpressionDescription_Conditional, 183RegexNodeKind.Capture => SR.ExpressionDescription_BalancingGroup, 184RegexNodeKind.ExpressionConditional => SR.ExpressionDescription_IfThenElse, 185RegexNodeKind.NegativeLookaround => SR.ExpressionDescription_NegativeLookaround, 186RegexNodeKind.PositiveLookaround => SR.ExpressionDescription_PositiveLookaround, 187RegexNodeKind.Start => SR.ExpressionDescription_ContiguousMatches, 195string description = $"Unexpected ({nameof(RegexNodeKind)}: {node.Kind})"; 211case RegexNodeKind.Concatenate: 221case RegexNodeKind.Alternate: 250case RegexNodeKind.Loop: 251case RegexNodeKind.Lazyloop: 260result.AddLast(_builder.CreateLoop(body, node.Kind == RegexNodeKind.Lazyloop, node.M, node.N)); 267Debug.Assert(node.Kind == RegexNodeKind.Capture && node.N == -1); 285Debug.Assert(rootResult.Count == 1 || root.Kind == RegexNodeKind.Concatenate || root.Kind == RegexNodeKind.Capture); 312Debug.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)
211findOptimizations.LeadingAnchor is not RegexNodeKind.Beginning)