CstNode

class CstNode

A CST node

Members defined in CstNode (23 members)

child_count

R

Get the node’s number of children.

descendant_count

R

Get the node’s number of descendants, including one for the node itself.

end_byte

R

Get the node’s end byte.

end_point

R

Get the node’s end position in terms of rows and columns (Utf-8 based).

grammar_symbol

R

Get the node’s type as a numerical id as it appears in the grammar ignoring aliases.

grammar_type

R

Get the node’s type as it appears in the grammar ignoring aliases as a null-terminated string.

has_changes

R

Check if a syntax node has been edited.

has_error

R

Check if the node is a syntax error or contains any syntax errors.

id

R

Get a numeric id for this node that is unique.

is_error

R

Check if the node is a syntax error.

is_extra

R

Check if the node is extra.

is_missing

R

Check if the node is missing.

is_named

R

Check if the node is named.

named_child_count

R

Get the node’s number of named children.

next_parse_state

R

Get the parse state after this node.

parse_state

R

Get this node’s parse state.

start_byte

R

Get the node’s start byte.

start_point

R

Get the node’s start position in terms of rows and columns (Utf-8 based).

string

R

Get an S-expression representing the node as a string.

symbol

R

Get the node’s type as a numerical id.

type

R

Get the node’s type as a string.

field_name_for_child

Get the field name for node’s child at the given index, where zero represents the first child.

text

Get the node’s source text.

Attributes

property child_count: int

Get the node’s number of children.

property descendant_count: int

Get the node’s number of descendants, including one for the node itself.

property end_byte: int

Get the node’s end byte.

property end_point: syside.PositionUtf8

Get the node’s end position in terms of rows and columns (Utf-8 based).

property grammar_symbol: syside.Symbol

Get the node’s type as a numerical id as it appears in the grammar ignoring aliases.

property grammar_type: str

Get the node’s type as it appears in the grammar ignoring aliases as a null-terminated string.

property has_changes: bool

Check if a syntax node has been edited.

property has_error: bool

Check if the node is a syntax error or contains any syntax errors.

property id: int

Get a numeric id for this node that is unique.

Within a given syntax tree, no two nodes have the same id. However:

  • If a new tree is created based on an older tree, and a node from the old tree is reused in the process, then that node will have the same id in both trees.

  • A node not marked as having changes does not guarantee it was reused.

  • If a node is marked as having changed in the old tree, it will not be reused.

property is_error: bool

Check if the node is a syntax error.

property is_extra: bool

Check if the node is extra.

Extra nodes represent things like comments, which are not required by the grammar, but can appear anywhere.

property is_missing: bool

Check if the node is missing.

Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.

property is_named: bool

Check if the node is named.

Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.

property named_child_count: int

Get the node’s number of named children.

property next_parse_state: syside.StateId

Get the parse state after this node.

property parse_state: syside.StateId

Get this node’s parse state.

property start_byte: int

Get the node’s start byte.

property start_point: syside.PositionUtf8

Get the node’s start position in terms of rows and columns (Utf-8 based).

property string: str

Get an S-expression representing the node as a string.

property symbol: syside.Symbol

Get the node’s type as a numerical id.

property type: str

Get the node’s type as a string.

Methods

field_name_for_child(arg: int, /) str | None

Get the field name for node’s child at the given index, where zero represents the first child.

Returns None, if no field is found

text(arg: str, /) str

Get the node’s source text.

This requires an explicit source text as it is not stored in the tree otherwise.

Used in