RegexSyntaxTree Class
A parsed regular expression.
public sealed class RegexSyntaxTree : SyntaxTreeRemarks
Parsing never throws. Whatever the pattern says, the tree reproduces it exactly, and anything wrong with it is reported through RegexSyntaxTree.GetDiagnostics.
- Inheritance
SyntaxTreeRegexSyntaxTree
Properties
| Name | Description |
|---|---|
| Captures | Gets the capture groups the pattern declares, in the order the engine numbers them. |
| Dialect | Gets the dialect the pattern was parsed as. |
| FilePath | |
| Options | |
| PatternOptions | Gets the options in effect at the start of the pattern, including any read from a literal's flags. |
Captures
RegexSyntaxTree.csGets the capture groups the pattern declares, in the order the engine numbers them.
public IReadOnlyList<RegexCaptureInfo> Captures { get; }Property value
Dialect
RegexSyntaxTree.csFilePath
RegexSyntaxTree.csOptions
RegexSyntaxTree.csPatternOptions
RegexSyntaxTree.csGets the options in effect at the start of the pattern, including any read from a literal's flags.
public RegexPatternOptions PatternOptions { get; }Property value
Methods
| Name | Description |
|---|---|
| GetChanges(SyntaxTree) | Returns the edit that turns oldTree's text into this tree's text. The common prefix and suffix are trimmed, so an edit in the middle of a pattern reports only the part that actually differs. |
| GetDiagnostics() | Gets everything the parser had to report, in source order. |
| GetRoot() | Gets the root of the tree. |
| GetText() | |
| IsEquivalentTo(RegexSyntaxTree?) | Compares this tree with other structurally, ignoring extended-mode whitespace and comments. Two patterns parsed as different dialects, or with different options, are never equivalent. |
| ParseJavaScriptLiteral(string) | Parses a JavaScript regular-expression literal such as /a+/giu, reading the flag letters into RegexSyntaxTree.PatternOptions and keeping the delimiters on the root so the literal round-trips. |
| ParseText(string, RegexDialect) | Parses pattern. Never throws; problems are reported as diagnostics. |
| ParseText(string, RegexParseOptions) | Parses pattern. Never throws; problems are reported as diagnostics. |
| WithChanges(TextChange[]) | Returns a tree over this pattern with changes applied. |
| WithChanges(IEnumerable<TextChange>) | Returns a tree over this pattern with changes applied. |
GetChanges(SyntaxTree)
RegexSyntaxTree.csReturns the edit that turns oldTree's text into this tree's text. The common prefix and suffix are trimmed, so an edit in the middle of a pattern reports only the part that actually differs.
public override IReadOnlyList<TextChange> GetChanges(SyntaxTree oldTree)Parameters
oldTreeSyntaxTree
Returns
Exceptions
ArgumentNullExceptionoldTreeisnull.
Remarks
This compares the two texts rather than the two trees. Every edit to a pattern reparses it, so the trees never share nodes and a structural comparison would report the whole pattern as replaced.
GetDiagnostics()
RegexSyntaxTree.csGets everything the parser had to report, in source order.
public override IReadOnlyList<Diagnostic> GetDiagnostics()Returns
GetRoot()
RegexSyntaxTree.csGetText()
RegexSyntaxTree.csIsEquivalentTo(RegexSyntaxTree?)
RegexSyntaxTree.csCompares this tree with other structurally, ignoring extended-mode whitespace and comments. Two patterns parsed as different dialects, or with different options, are never equivalent.
public bool IsEquivalentTo(RegexSyntaxTree? other)Parameters
otherRegexSyntaxTree?
Returns
Remarks
Identical text is a shortcut only when the options match as well. The same characters read with and without RegexPatternOptions.IgnorePatternWhitespace are different trees -- a space is a term in one and trivia in the other -- so comparing the text alone would call them equivalent.
ParseJavaScriptLiteral(string)
RegexSyntaxTree.csParses a JavaScript regular-expression literal such as /a+/giu, reading the flag letters into RegexSyntaxTree.PatternOptions and keeping the delimiters on the root so the literal round-trips.
public static RegexSyntaxTree ParseJavaScriptLiteral(string literal)Parameters
literalstring
Returns
Remarks
The dialect is always RegexDialect.JavaScript: only that dialect has literals. Text that follows the flags is reported as REGEX0204 and kept as skipped text.
ParseText overloads
ParseText(string, RegexDialect)
RegexSyntaxTree.csParses pattern. Never throws; problems are reported as diagnostics.
public static RegexSyntaxTree ParseText(string pattern, RegexDialect dialect)ParseText(string, RegexParseOptions)
RegexSyntaxTree.csParses pattern. Never throws; problems are reported as diagnostics.
public static RegexSyntaxTree ParseText(string pattern, RegexParseOptions options)Parameters
patternstringoptionsRegexParseOptions
Returns
Exceptions
ArgumentNullExceptionoptionsisnull.
WithChanges overloads
WithChanges(TextChange[])
RegexSyntaxTree.csReturns a tree over this pattern with changes applied.
public RegexSyntaxTree WithChanges(params TextChange[] changes)WithChanges(IEnumerable<TextChange>)
RegexSyntaxTree.csReturns a tree over this pattern with changes applied.
public RegexSyntaxTree WithChanges(IEnumerable<TextChange> changes)