AstNode

Description

struct Tinman.Core.Parsing.AstNode

Derived from

IEquatable<AstNode>

Represents a node of an abstract syntax tree (AST).

Public / Constants

Null


public static readonly attribute Null → (AstNode)

The special AstNode value that represents no AST node.

Public / Methods

Check​Count


public method CheckCount → (3)

input in : ICodeInput

[not-null]
The code input, for error reporting.

minimum opt : int32 = 0

[>=0]
The minimum number of child nodes.

maximum opt : int32 = 0

[>=0]
The maximum number of child nodes. Set to 0 to disable this check. Defaults to 0.

Checks if the number of child nodes (see Count) is within the given range.

ValidatingException

If the check has failed.

Check​Type


public method CheckType → (2)

input in : ICodeInput

[not-null]
The code input, for error reporting.

expectedType in : string

[not-empty]
The expected node type.

Checks if the type of this node if equal to the given one.

ValidatingException

If the check has failed.

Check​Value


public method CheckValue → (2)

input in : ICodeInput

[not-null]
The code input, for error reporting.

expectedValue in : string

[not-null]
The expected value.

Checks if the textual value of this node in the code input matches the given expected value.

ValidatingException

If the check has failed.

Child

2 overloads


[Pure]
public method Child1 → (1)

type in : string

[not-null]
The token type.

returns → AstNode

The first matching child node or Null.

Returns the first child node that has the given token type.


[Pure]
public method Child2 → (1)

in : int32

[0..AstNode.Children.Length-1]
Index of child node.

returns → AstNode

The child node.

Returns the n-th child node, assuming that it exists.

Extract


public method Extract → (1)

sourceCode in : string

[not-null]
The source code string.

returns → string

The AST node range in sourceCode in or null iff this value is Null.

Extracts the range of this AST node from the given string.

The given string must be identical to the parser input (e.g. see CodeInput).

See also

IText.CharsAt

To​String​Grammar


public method ToStringGrammar → ()

returns → string

The textual dump string or null iff this value is Null.

Generates a textual dump of the AST node hierarchy.

To​String​Tree

2 overloads


public method ToStringTree1 → ()

returns → string

The string representation.

Returns a human-readable string representation of the AST node tree.


public method ToStringTree2 → (1)

input in : string

Optional parser input string for more detailed dump.

returns → string

The string representation.

Returns a human-readable string representation of the AST node tree.

Value

2 overloads


[Pure]
public method Value1 → (1)

input in : string

[not-null]
The code input.

returns → string

The node value.

Returns the value of this AST node.


[Pure]
public method Value2 → (1)

input in : ICodeInput

[not-null]
The code input.

returns → string

The node value.

Returns the value of this AST node.

Public / Attributes

Children


public attribute Children → (get)

value : AstNode [ ]

[not-null]
The child nodes. Will be empty for Null.

Returns the child nodes of this AST node.

Count


public attribute Count → (get)

value : int32

[>=0]
The number of child nodes. Will be 0 for Null.

Returns the number of child nodes.

End


public attribute End → (get)

value : int32

[>=0]
The token index. Will be 0 for Null.

Index of last input token that belongs to this AST node (exclusive).

First


public attribute First → (get)

value : AstNode

The first child node or Null if it does not exist.

Returns the first child node (index 0).

Is​Not​Null


public attribute IsNotNull → (get)

value : bool

true if this AstNode value is not Null,
false if it is.

Is this not the Null value?

See also

AstNode.IsNull

Is​Null


public attribute IsNull → (get)

value : bool

true if this AstNode value is Null,
false if it is not.

Is this the Null value?

Last


public attribute Last → (get)

value : AstNode

The last child node or Null if it does not exist.

Returns the last child node.

Range


public attribute Range → (get)

value : RangeI

The code range or RangeI.Inv iff this value is Null.

The range of this AST node in the input source code.

See also

ICodeRange

Second


public attribute Second → (get)

value : AstNode

The first child node or Null if it does not exist.

Returns the first child node (index 1).

Start


public attribute Start → (get)

value : int32

[>=-1]
The token index. Will be -1 iff this value is Null.

Index of first input token that belongs to this AST node (inclusive).

Third


public attribute Third → (get)

value : AstNode

The first child node or Null if it does not exist.

Returns the first child node (index 2).

Type


public attribute Type → (get)

value : string

The token type or null iff this value is Null.

The input token type.