ShellSyntaxTree Class
A shell script read from source text, together with what is wrong with it.
public sealed class ShellSyntaxTree : SyntaxTreeExample
var tree = ShellSyntaxTree.ParseText("ls -l | wc -l", ShellDialect.Bash);
var updated = tree.WithChanges(new TextChange(new TextSpan(0, 2), "dir"));
Assert.Equal("dir -l | wc -l", updated.GetText().Text);- Inheritance
SyntaxTreeShellSyntaxTree
Properties
| Name | Description |
|---|---|
| Dialect | Gets the dialect the text was read as. |
| FilePath | |
| Options |
Dialect
ShellSyntaxTree.csFilePath
ShellSyntaxTree.csOptions
ShellSyntaxTree.csMethods
| 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 script reports only the part that actually differs. |
| GetDiagnostics() | Gets everything wrong with the script, in the order the parser found it. |
| GetRoot() | Gets the script this tree holds. |
| GetText() | |
| IsEquivalentTo(ShellSyntaxTree?) | Compares this tree with other structurally, ignoring whitespace and comments. Two scripts that differ only in formatting are equivalent; two scripts parsed as different dialects never are. |
| ParseCommand(string, ShellDialect) | Parses text as a single command, pipeline, or command list. Content after the first statement is reported as SHELL0101 and kept as skipped text so the backing tree still round-trips. |
| ParseCommand(string, ShellParseOptions) | Parses text as a single command, pipeline, or command list. Content after the first statement is reported as SHELL0101 and kept as skipped text so the backing tree still round-trips. |
| ParseText(string, ShellDialect) | Parses text as a complete script. Never throws; problems are reported as diagnostics. |
| ParseText(string, ShellParseOptions) | Parses text as a complete script. Never throws; problems are reported as diagnostics. |
| WithChanges(TextChange[]) | |
| WithChanges(IEnumerable<TextChange>) |
GetChanges(SyntaxTree)
ShellSyntaxTree.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 script 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. Editing by text reparses, so the trees never share nodes and a structural comparison would report the whole script as replaced.
GetDiagnostics()
ShellSyntaxTree.csGets everything wrong with the script, in the order the parser found it.
public override IReadOnlyList<Diagnostic> GetDiagnostics()Returns
GetRoot()
ShellSyntaxTree.csGetText()
ShellSyntaxTree.csIsEquivalentTo(ShellSyntaxTree?)
ShellSyntaxTree.csCompares this tree with other structurally, ignoring whitespace and comments. Two scripts that differ only in formatting are equivalent; two scripts parsed as different dialects never are.
public bool IsEquivalentTo(ShellSyntaxTree? other)ParseCommand overloads
ParseCommand(string, ShellDialect)
ShellSyntaxTree.csParses text as a single command, pipeline, or command list. Content after the first statement is reported as SHELL0101 and kept as skipped text so the backing tree still round-trips.
public static ShellStatementSyntax ParseCommand(string text, ShellDialect dialect)ParseCommand(string, ShellParseOptions)
ShellSyntaxTree.csParses text as a single command, pipeline, or command list. Content after the first statement is reported as SHELL0101 and kept as skipped text so the backing tree still round-trips.
public static ShellStatementSyntax ParseCommand(string text, ShellParseOptions options)Parameters
textstringoptionsShellParseOptions
Returns
Exceptions
ArgumentNullExceptionoptionsisnull.
ParseText overloads
ParseText(string, ShellDialect)
ShellSyntaxTree.csParses text as a complete script. Never throws; problems are reported as diagnostics.
public static ShellSyntaxTree ParseText(string text, ShellDialect dialect)ParseText(string, ShellParseOptions)
ShellSyntaxTree.csParses text as a complete script. Never throws; problems are reported as diagnostics.
public static ShellSyntaxTree ParseText(string text, ShellParseOptions options)Parameters
textstringoptionsShellParseOptions
Returns
Exceptions
ArgumentNullExceptionoptionsisnull.
WithChanges overloads
WithChanges(TextChange[])
ShellSyntaxTree.cspublic ShellSyntaxTree WithChanges(params TextChange[] changes)WithChanges(IEnumerable<TextChange>)
ShellSyntaxTree.cspublic ShellSyntaxTree WithChanges(IEnumerable<TextChange> changes)