Module tree_sitter_graph::reference::functions
source · [−]Expand description
This section defines the standard library of functions available to graph DSL files.
Note that the process that is executing the graph DSL file has control over which function it provides. Most of the time, you will have (at least) the functions defined here available. There might be additional functions available, and in rare cases, there might be a completely different set of functions available!
General functions
is-null
Check if an optional value is missing.
- Input parameters: one value
- Output: a boolean indicating whether the value is null or not
Graph manipulation functions
node
Creates a new graph node.
- Input parameters: none
- Output: a reference to the new graph node
Logical functions
not
Negates a boolean value.
- Input parameters: one boolean
- Output: the negation of the input value
and
Computes the conjunction of boolean values: true if none of the inputs are false, otherwise false.
- Input parameters: zero or more booleans
- Output: the conjunction of all the input booleans
or
Computes the disjunction of boolean values: true if any of the inputs are true, otherwise false.
- Input parameters: zero or more booleans
- Output: the disjunction of all the input booleans
Mathematical functions
plus
Adds integers together.
- Input parameters: zero or more integers
- Output: the sum of all of the input integers
String functions
replace
Applies a regular expression to a string, replacing any text that matches.
- Input parameters:
text
: a string to look for matches inpattern
: a string defining the regular expression to search forreplacement
: the text to replace any matches with
Note that the regular expression syntax that we support is exactly that used by Rust’s
regex
crate. In particular, the pattern
is passed in to Regex::new
, and the
replacement
text passed in to Regex::replace_all
.
List functions
is-empty
Test whether a list is empty or not.
- Input parameters: a list value
- Output parameters: a boolean indicating whether the list is empty or not
length
Determine the length of a list.
- Input parameters: a list value
- Output parameters: an integer indicating the length of the list
Syntax manipulation functions
named-child-index
Returns the index of a “named child” within its parent.
- Input parameters:
node
: A syntax node
- Output parameter:
- The index of
node
within its parent’s list of named children (i.e., the index that would causets_node_named_child
to returnnode
)
- The index of
named-child-count
Returns the number of “named children” of a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- The number of named children in
node
- The number of named children in
source-text
Returns the source text represented by a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- A string containing the source text represented by
node
- A string containing the source text represented by
node-type
Returns a syntax node’s type as a string. (The type is the name of the node’s grammar rule in the underlying tree-sitter grammar.)
- Input parameters:
node
: A syntax node
- Output parameter:
- A string containing the type of
node
- A string containing the type of
start-column
Returns the zero-based start column of a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- The zero-based start column of
node
- The zero-based start column of
start-row
Returns the zero-based start row of a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- The zero-based start row of
node
- The zero-based start row of
end-column
Returns the zero-based end column of a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- The zero-based end column of
node
- The zero-based end column of
end-row
Returns the zero-based end row of a syntax node.
- Input parameters:
node
: A syntax node
- Output parameter:
- The zero-based end row of
node
- The zero-based end row of