tree_sitter_graph/reference/functions.rs
1// -*- coding: utf-8 -*-
2// ------------------------------------------------------------------------------------------------
3// Copyright © 2021, tree-sitter authors.
4// Licensed under either of Apache License, Version 2.0, or MIT license, at your option.
5// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
6// ------------------------------------------------------------------------------------------------
7
8//! This section defines the standard library of functions available to graph DSL files.
9//!
10//! Note that the process that is executing the graph DSL file has control over which function it
11//! provides. Most of the time, you will have (at least) the functions defined here available.
12//! There might be additional functions available, and in rare cases, there might be a completely
13//! different set of functions available!
14//!
15//! # General functions
16//!
17//! ## `eq`
18//!
19//! Check if values are equal.
20//!
21//! - Input parameters: two values
22//! - Output value: a boolean indicating whether the values are equal or not
23//!
24//! The compared values must be of the same type. Null values are equal to each
25//! other and can be compared to values of any type.
26//!
27//! ## `is-null`
28//!
29//! Check if an optional value is missing.
30//!
31//! - Input parameters: one value
32//! - Output value: a boolean indicating whether the value is null or not
33//!
34//! # Graph manipulation functions
35//!
36//! ## `node`
37//!
38//! Creates a new graph node.
39//!
40//! - Input parameters: none
41//! - Output value: a reference to the new graph node
42//!
43//! # Logical functions
44//!
45//! ## `not`
46//!
47//! Negates a boolean value.
48//!
49//! - Input parameters: one boolean
50//! - Output value: the negation of the input value
51//!
52//! ## `and`
53//!
54//! Computes the conjunction of boolean values:
55//! true if none of the inputs are false, otherwise false.
56//!
57//! - Input parameters: zero or more booleans
58//! - Output value: the conjunction of all the input booleans
59//!
60//! ## `or`
61//!
62//! Computes the disjunction of boolean values:
63//! true if any of the inputs are true, otherwise false.
64//!
65//! - Input parameters: zero or more booleans
66//! - Output value: the disjunction of all the input booleans
67//!
68//! # Mathematical functions
69//!
70//! ## `plus`
71//!
72//! Adds integers together.
73//!
74//! - Input parameters: zero or more integers
75//! - Output value: the sum of all of the input integers
76//!
77//! # String functions
78//!
79//! ## `format`
80//!
81//! Formats a string according to the given format string and arguments.
82//!
83//! - Input parameters:
84//! - `format`: a format string containing placeholders
85//! - as many additional parameters as there are placeholders in the format string
86//!
87//! - Output value: a formatted string with the placeholders replaced by formatted values
88//!
89//! Placeholders are written as `{}`. To produce literal braces, use `{{` and `}}` instead.
90//!
91//! ## `replace`
92//!
93//! Applies a regular expression to a string, replacing any text that matches.
94//!
95//! - Input parameters:
96//! - `text`: a string to look for matches in
97//! - `pattern`: a string defining the regular expression to search for
98//! - `replacement`: the text to replace any matches with
99//!
100//! Note that the regular expression syntax that we support is exactly that used by Rust's
101//! [`regex`][] crate. In particular, the `pattern` is passed in to [`Regex::new`][], and the
102//! `replacement` text passed in to [`Regex::replace_all`][].
103//!
104//! [`regex`]: https://docs.rs/regex/
105//! [`Regex::new`]: https://docs.rs/regex/*/regex/struct.Regex.html#method.new
106//! [`Regex::replace_all`]: https://docs.rs/regex/*/regex/struct.Regex.html#method.replace_all
107//!
108//! # List functions
109//!
110//! ## `concat`
111//!
112//! Concatenate list arguments.
113//!
114//! - Input parameters: list values
115//! - Output value: the concatenation of the input lists
116//!
117//! ## `is-empty`
118//!
119//! Test whether a list is empty or not.
120//!
121//! - Input parameters: a list value
122//! - Output value: a boolean indicating whether the list is empty or not
123//!
124//! ## `join`
125//!
126//! Join a list of values using the given separator
127//!
128//! - Input parameters:
129//! - `list`: A list of values
130//! - `sep`: An optional separator string
131//! - Output value:
132//! - A string consisting of the formatted values from the list separated by
133//! the separator string
134//!
135//! ## `length`
136//!
137//! Determine the length of a list.
138//!
139//! - Input parameters: a list value
140//! - Output value: an integer indicating the length of the list
141//!
142//! # Syntax manipulation functions
143//!
144//! ## `named-child-index`
145//!
146//! Returns the index of a "named child" within its parent.
147//!
148//! - Input parameters:
149//! - `node`: A syntax node
150//! - Output value:
151//! - The index of `node` within its parent's list of _named_ children (i.e., the index that
152//! would cause `ts_node_named_child` to return `node`)
153//!
154//! ## `named-child-count`
155//!
156//! Returns the number of "named children" of a syntax node.
157//!
158//! - Input parameters:
159//! - `node`: A syntax node
160//! - Output value:
161//! - The number of _named_ children in `node`
162//!
163//! ## `source-text`
164//!
165//! Returns the source text represented by a syntax node.
166//!
167//! - Input parameters:
168//! - `node`: A syntax node
169//! - Output value:
170//! - A string containing the source text represented by `node`
171//!
172//! ## `node-type`
173//!
174//! Returns a syntax node's type as a string. (The type is the name of the node's grammar rule in
175//! the underlying tree-sitter grammar.)
176//!
177//! - Input parameters:
178//! - `node`: A syntax node
179//! - Output value:
180//! - A string containing the type of `node`
181//!
182//! ## `start-column`
183//!
184//! Returns the zero-based start column of a syntax node.
185//!
186//! - Input parameters:
187//! - `node`: A syntax node
188//! - Output value:
189//! - The zero-based start column of `node`
190//!
191//! ## `start-row`
192//!
193//! Returns the zero-based start row of a syntax node.
194//!
195//! - Input parameters:
196//! - `node`: A syntax node
197//! - Output value:
198//! - The zero-based start row of `node`
199//!
200//! ## `end-column`
201//!
202//! Returns the zero-based end column of a syntax node.
203//!
204//! - Input parameters:
205//! - `node`: A syntax node
206//! - Output value:
207//! - The zero-based end column of `node`
208//!
209//! ## `end-row`
210//!
211//! Returns the zero-based end row of a syntax node.
212//!
213//! - Input parameters:
214//! - `node`: A syntax node
215//! - Output value:
216//! - The zero-based end row of `node`