ShellSyntaxTree Class

A shell script read from source text, together with what is wrong with it.

public sealed class ShellSyntaxTree : SyntaxTree

Example

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
SyntaxTree ShellSyntaxTree

Properties

NameDescription
DialectGets the dialect the text was read as.
FilePath
Options

Gets the dialect the text was read as.

public ShellDialect Dialect { get; }

Property value

ShellDialect

public override string? FilePath { get; }

Property value

string?

No documentation is available.

public ShellParseOptions Options { get; }

Property value

ShellParseOptions

No documentation is available.

Methods

NameDescription
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.cs

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.

public override IReadOnlyList<TextChange> GetChanges(SyntaxTree oldTree)

Parameters

oldTree SyntaxTree

Returns

IReadOnlyList<TextChange>

Exceptions

ArgumentNullException
oldTree is null.

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.cs

Gets everything wrong with the script, in the order the parser found it.

public override IReadOnlyList<Diagnostic> GetDiagnostics()

Gets the script this tree holds.

public ShellScriptSyntax GetRoot()
public override SourceText GetText()

Returns

SourceText

No documentation is available.

IsEquivalentTo(ShellSyntaxTree?)

ShellSyntaxTree.cs

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.

public bool IsEquivalentTo(ShellSyntaxTree? other)

Parameters

other ShellSyntaxTree?

Returns

bool

ParseCommand overloads

ParseCommand(string, ShellDialect)

ShellSyntaxTree.cs

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.

public static ShellStatementSyntax ParseCommand(string text, ShellDialect dialect)
Parameters
text string
dialect ShellDialect
Returns

ShellStatementSyntax

Exceptions
ArgumentNullException
dialect is null.

ParseCommand(string, ShellParseOptions)

ShellSyntaxTree.cs

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.

public static ShellStatementSyntax ParseCommand(string text, ShellParseOptions options)
Parameters
text string
options ShellParseOptions
Returns

ShellStatementSyntax

Exceptions
ArgumentNullException
options is null.

ParseText overloads

ParseText(string, ShellDialect)

ShellSyntaxTree.cs

Parses text as a complete script. Never throws; problems are reported as diagnostics.

public static ShellSyntaxTree ParseText(string text, ShellDialect dialect)
Parameters
text string
dialect ShellDialect
Returns

ShellSyntaxTree

Exceptions
ArgumentNullException
dialect is null.

ParseText(string, ShellParseOptions)

ShellSyntaxTree.cs

Parses text as a complete script. Never throws; problems are reported as diagnostics.

public static ShellSyntaxTree ParseText(string text, ShellParseOptions options)
Parameters
text string
options ShellParseOptions
Returns

ShellSyntaxTree

Exceptions
ArgumentNullException
options is null.

WithChanges overloads

WithChanges(TextChange[])

ShellSyntaxTree.cs
public ShellSyntaxTree WithChanges(params TextChange[] changes)
Parameters
changes TextChange[]
Returns

ShellSyntaxTree

Exceptions
ArgumentNullException
changes is null.

WithChanges(IEnumerable<TextChange>)

ShellSyntaxTree.cs
public ShellSyntaxTree WithChanges(IEnumerable<TextChange> changes)
Parameters
changes IEnumerable<TextChange>
Returns

ShellSyntaxTree

Exceptions
ArgumentNullException
changes is null.