RegexGenerator.Parser.cs (19)
141RegexOptions regexOptions = options is not null ? (RegexOptions)options : RegexOptions.None;
150RegexOptions regexOptionsWithPatternOptions;
160if ((regexOptionsWithPatternOptions & RegexOptions.IgnoreCase) != 0 && !string.IsNullOrEmpty(cultureName))
162if ((regexOptions & RegexOptions.CultureInvariant) != 0)
179const RegexOptions SupportedOptions =
180RegexOptions.Compiled |
181RegexOptions.CultureInvariant |
182RegexOptions.ECMAScript |
183RegexOptions.ExplicitCapture |
184RegexOptions.IgnoreCase |
185RegexOptions.IgnorePatternWhitespace |
186RegexOptions.Multiline |
187RegexOptions.NonBacktracking |
188RegexOptions.RightToLeft |
189RegexOptions.Singleline;
252internal sealed record RegexPatternAndSyntax(RegexType DeclaringType, bool IsProperty, Location DiagnosticLocation, string MemberName, string Modifiers, bool NullableRegex, string Pattern, RegexOptions Options, int? MatchTimeout, CultureInfo Culture, CompilationData CompilationData);
255internal sealed record RegexMethod(RegexType DeclaringType, bool IsProperty, string MemberName, string Modifiers, bool NullableRegex, string Pattern, RegexOptions Options, int? MatchTimeout, RegexTree Tree, AnalysisResults Analysis, CompilationData CompilationData)
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexNode.cs (53)
42public RegexOptions Options;
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)
110public static RegexNode CreateOneWithCaseConversion(char ch, RegexOptions options, CultureInfo? culture, ref RegexCaseBehavior caseBehavior)
113if ((options & RegexOptions.IgnoreCase) != 0)
121return new RegexNode(RegexNodeKind.One, options & ~RegexOptions.IgnoreCase, ch);
127return new RegexNode(RegexNodeKind.Set, options & ~RegexOptions.IgnoreCase, stringSet);
137if ((Options & RegexOptions.RightToLeft) != 0 &&
355Debug.Assert((node.Options & RegexOptions.IgnoreCase) == 0, $"{node.Kind} node should not have RegexOptions.IgnoreCase");
379if ((rootNode.Options & (RegexOptions.RightToLeft | RegexOptions.NonBacktracking)) == 0)
454(Options & RegexOptions.NonBacktracking) != 0)
469bool rtl = (node.Options & RegexOptions.RightToLeft) != 0;
581Options &= ~RegexOptions.IgnoreCase;
652if ((Options & RegexOptions.NonBacktracking) != 0)
696if ((Options & RegexOptions.RightToLeft) == 0)
1071RegexOptions optionsLast = 0;
1072RegexOptions optionsAt;
1109optionsAt = at.Options & (RegexOptions.RightToLeft | RegexOptions.IgnoreCase);
1157if ((prev.Options & RegexOptions.IgnoreCase) != 0)
1159prev.Options &= ~RegexOptions.IgnoreCase;
1191if ((alternation.Options & RegexOptions.RightToLeft) != 0)
1339if ((alternation.Options & RegexOptions.RightToLeft) != 0)
1354RegexOptions startingNodeOptions = startingNode.Options;
1500Debug.Assert((Options & RegexOptions.RightToLeft) == 0);
1515Debug.Assert((Options & RegexOptions.RightToLeft) == 0);
1580if (node is not null && (node.Options & RegexOptions.RightToLeft) == 0)
1730RegexOptions optionsLast = 0;
1744((at.Options & RegexOptions.RightToLeft) == (Options & RegexOptions.RightToLeft)))
1765RegexOptions optionsAt = at.Options & (RegexOptions.RightToLeft | RegexOptions.IgnoreCase);
1782prev.Str = (optionsAt & RegexOptions.RightToLeft) == 0 ?
1891(nextNode.Options & RegexOptions.RightToLeft) == 0 && // RTL multi nodes don't have their text reversed, and it's not worth the code to optimize further
1992Debug.Assert((Options & RegexOptions.NonBacktracking) == 0, "Atomic groups aren't supported and don't help performance with NonBacktracking");
2027(node.Options & RegexOptions.RightToLeft) != 0)
2219if (((Options & RegexOptions.RightToLeft) == 0 && IsZeroWidthAssertion(child.Kind)) ||
2319if (condition.Kind == RegexNodeKind.PositiveLookaround && (condition.Options & RegexOptions.RightToLeft) == 0)
2378case RegexNodeKind.PositiveLookaround when (subsequent.Options & RegexOptions.RightToLeft) == 0:
2656if ((node.Options & RegexOptions.RightToLeft) != 0 ||
3218if ((Options & RegexOptions.NonBacktracking) != 0)
3309if ((Options & RegexOptions.ExplicitCapture) != 0) sb.Append("-C");
3310if ((Options & RegexOptions.IgnoreCase) != 0) sb.Append("-I");
3311if ((Options & RegexOptions.RightToLeft) != 0) sb.Append("-L");
3312if ((Options & RegexOptions.Multiline) != 0) sb.Append("-M");
3313if ((Options & RegexOptions.Singleline) != 0) sb.Append("-S");
3314if ((Options & RegexOptions.IgnorePatternWhitespace) != 0) sb.Append("-X");
3315if ((Options & RegexOptions.ECMAScript) != 0) sb.Append("-E");
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexNodeKind.cs (14)
18/// <summary>Anything other than a specific character, e.g. `.` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]`.</summary>
35/// <summary>A loop around anything other than a specific character, e.g. `.*` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]*`.</summary>
48/// <summary>A lazy loop around anything other than a specific character, e.g. `.*?` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]*?`.</summary>
63/// <summary>An atomic loop around anything other than a specific character, e.g. `(?>.*)` when not in <see cref="RegexOptions.Singleline"/> mode.</summary>
80/// <summary>A beginning-of-line anchor, e.g. `^` in <see cref="RegexOptions.Multiline"/> mode.</summary>
82/// <summary>An end-of-line anchor, e.g. `$` in <see cref="RegexOptions.Multiline"/> mode.</summary>
88/// <summary>A word boundary anchor, e.g. `\b` in <see cref="RegexOptions.ECMAScript"/> mode.</summary>
90/// <summary>Not a word boundary anchor, e.g. `\B` in <see cref="RegexOptions.ECMAScript"/> mode..</summary>
92/// <summary>A beginning-of-string anchor, e.g. `\A`, or `^` when not in <see cref="RegexOptions.Multiline"/> mode.</summary>
96/// <summary>A end-of-string-or-before-ending-newline anchor, e.g. `\Z`, or `$` when not in <see cref="RegexOptions.Multiline"/> mode.</summary>
156/// A positive lookaround assertion: lookahead if <see cref="RegexOptions.RightToLeft"/> is not set and lookbehind if
157/// <see cref="RegexOptions.RightToLeft"/> is set, e.g. `(?=abc)` or `(?<=abc)`.</summary>
161/// A negative lookaround assertion: lookahead if <see cref="RegexOptions.RightToLeft"/> is not set and lookbehind if
162/// <see cref="RegexOptions.RightToLeft"/> is set, e.g. `(?!abc)` or `(?<!abc)`.</summary>
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexParser.cs (71)
47private RegexOptions _options;
55private RegexParser(string pattern, RegexOptions options, CultureInfo culture, Hashtable caps, int capsize, Hashtable? capnames, Span<int> optionSpan)
85internal static CultureInfo GetTargetCulture(RegexOptions options) =>
87(options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture;
90public static RegexOptions ParseOptionsInPattern(string pattern, RegexOptions options)
98parser.CountCaptures(out RegexOptions foundOptionsInPattern);
103public static RegexTree Parse(string pattern, RegexOptions options, CultureInfo culture)
137public static RegexReplacement ParseReplacement(string pattern, RegexOptions options, Hashtable caps, int capsize, Hashtable capnames)
140CultureInfo culture = (options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture;
223var parser = new RegexParser(input, RegexOptions.None, CultureInfo.InvariantCulture, new Hashtable(), 0, null, stackalloc int[OptionStackDefaultSize]);
257private void Reset(RegexOptions options)
277StartGroup(new RegexNode(RegexNodeKind.Capture, (_options & ~RegexOptions.IgnoreCase), 0, -1));
290if ((_options & RegexOptions.IgnorePatternWhitespace) != 0)
346string setString = ScanCharClass((_options & RegexOptions.IgnoreCase) != 0, scanOnly: false)!.ToStringClass();
347_unit = new RegexNode(RegexNodeKind.Set, _options & ~RegexOptions.IgnoreCase, setString);
376_options = (RegexOptions)_optionsStack.Pop();
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);
402_unit = (_options & RegexOptions.Singleline) != 0 ?
403new RegexNode(RegexNodeKind.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.AnyClass) :
404new RegexNode(RegexNodeKind.Notone, _options & ~RegexOptions.IgnoreCase, '\n');
571if ((_options & RegexOptions.ECMAScript) != 0 && _pattern[_pos] == ']')
591if ((_options & RegexOptions.ECMAScript) != 0 && _pos < _pattern.Length && _pattern[_pos] == ']')
649charClass!.AddDigit((_options & RegexOptions.ECMAScript) != 0, ch == 'D', _pattern, _pos);
661charClass!.AddSpace((_options & RegexOptions.ECMAScript) != 0, ch == 'S');
674charClass!.AddWord((_options & RegexOptions.ECMAScript) != 0, ch == 'W');
803if ((_options & RegexOptions.ExplicitCapture) != 0 || _ignoreNextParen)
835_options &= ~RegexOptions.RightToLeft;
841_options &= ~RegexOptions.RightToLeft;
869_options |= RegexOptions.RightToLeft;
880_options |= RegexOptions.RightToLeft;
1088if ((_options & RegexOptions.IgnorePatternWhitespace) != 0)
1096if ((_options & RegexOptions.IgnorePatternWhitespace) != 0 && _pos < _pattern.Length && _pattern[_pos] == '#')
1143new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMAWordClass : RegexCharClass.WordClass);
1148new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMAWordClass : RegexCharClass.NotWordClass);
1153new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMASpaceClass : RegexCharClass.SpaceClass);
1158new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMASpaceClass : RegexCharClass.NotSpaceClass);
1163new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMADigitClass : RegexCharClass.DigitClass);
1168new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMADigitClass : RegexCharClass.NotDigitClass);
1179cc.AddCategoryFromName(ParseProperty(), ch != 'p', (_options & RegexOptions.IgnoreCase) != 0, _pattern, _pos);
1180if ((_options & RegexOptions.IgnoreCase) != 0)
1185return new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), cc.ToStringClass());
1189if (result != null && result.Kind == RegexNodeKind.Backreference && (result.Options & RegexOptions.IgnoreCase) != 0)
1259if ((_options & RegexOptions.ECMAScript) != 0)
1361if (!angled && (_options & RegexOptions.ECMAScript) != 0)
1490if ((_options & RegexOptions.ECMAScript) != 0 && i >= 0x20)
1594RegexOptions options = (char)(ch | 0x20) switch
1596'i' => RegexOptions.IgnoreCase,
1597'm' => RegexOptions.Multiline,
1598'n' => RegexOptions.ExplicitCapture,
1599's' => RegexOptions.Singleline,
1600'x' => RegexOptions.IgnorePatternWhitespace,
1601_ => RegexOptions.None,
1656if ((_options & RegexOptions.ECMAScript) == 0 && RegexCharClass.IsBoundaryWordChar(ch))
1703'b' => (_options & RegexOptions.ECMAScript) != 0 ? RegexNodeKind.ECMABoundary : RegexNodeKind.Boundary,
1704'B' => (_options & RegexOptions.ECMAScript) != 0 ? RegexNodeKind.NonECMABoundary : RegexNodeKind.NonBoundary,
1715private void CountCaptures(out RegexOptions optionsFoundInPattern)
1718optionsFoundInPattern = RegexOptions.None;
1735if ((_options & RegexOptions.IgnorePatternWhitespace) != 0)
1749_options = (RegexOptions)_optionsStack.Pop();
1820if ((_options & RegexOptions.ExplicitCapture) == 0 && !_ignoreNextParen)
2047_concatenation!.AddChild(RegexNode.CreateOneWithCaseConversion(_pattern[pos], isReplacement ? _options & ~RegexOptions.IgnoreCase : _options, _culture, ref _caseBehavior));
2050case > 1 when (_options & RegexOptions.IgnoreCase) == 0 || isReplacement || !RegexCharClass.ParticipatesInCaseConversion(_pattern.AsSpan(pos, cch)):
2051_concatenation!.AddChild(new RegexNode(RegexNodeKind.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch)));