package tree-sitter
- License: MIT
- Repository: https://github.com/laytan/odin-tree-sitter/blob/main
Index
Types (37)
- Compat_Allocator
- Decode_Function
- Field_Id
- File_Input
- Input
- Input_Edit
- Input_Encoding
- Language
- Language_Metadata
- Log_Type
- Logger
- Lookahead_Iterator
- Node
- Parse_Options
- Parse_State
- Parser
- Point
- Quantifier
- Query
- Query_Capture
- Query_Cursor
- Query_Cursor_Options
- Query_Cursor_State
- Query_Error
- Query_Match
- Query_Predicate_Step
- Query_Predicate_Step_Type
- Range
- State_Id
- Symbol
- Symbol_Type
- Tree
- Tree_Cursor
- Wasm_Engine
- Wasm_Error
- Wasm_Error_Kind
- Wasm_Store
Constants (2)
Variables (0)
This section is empty.
Procedures (153)
- file_input
- language_abi_version
- language_copy
- language_delete
- language_field_count
- language_field_id_for_name
- language_field_name_for_id
- language_is_wasm
- language_metadata
- language_name
- language_next_state
- language_state_count
- language_subtypes
- language_supertypes
- language_symbol_count
- language_symbol_for_name
- language_symbol_name
- language_symbol_type
- lookahead_iterator_current_symbol
- lookahead_iterator_current_symbol_name
- lookahead_iterator_delete
- lookahead_iterator_language
- lookahead_iterator_new
- lookahead_iterator_next
- lookahead_iterator_reset
- lookahead_iterator_reset_state
- node_child
- node_child_by_field_id
- node_child_by_field_name
- node_child_count
- node_child_with_descendant
- node_descendant_count
- node_descendant_for_byte_range
- node_descendant_for_point_range
- node_edit
- node_end_byte
- node_end_point
- node_eq
- node_field_name_for_child
- node_field_name_for_named_child
- node_first_child_for_byte
- node_first_named_child_for_byte
- node_grammar_symbol
- node_grammar_type
- node_has_changes
- node_has_error
- node_is_error
- node_is_extra
- node_is_missing
- node_is_named
- node_is_null
- node_language
- node_named_child
- node_named_child_count
- node_named_descendant_for_byte_range
- node_named_descendant_for_point_range
- node_next_named_sibling
- node_next_parse_state
- node_next_sibling
- node_parent
- node_parse_state
- node_prev_named_sibling
- node_prev_sibling
- node_start_byte
- node_start_point
- node_string
- node_symbol
- node_text
- node_type
- parser_delete
- parser_included_ranges
- parser_language
- parser_logger
- parser_new
- parser_parse
- parser_parse_string
- parser_parse_string_encoding
- parser_parse_with_options
- parser_print_dot_graphs
- parser_reset
- parser_set_included_ranges
- parser_set_language
- parser_set_logger
- parser_set_odin_logger
- parser_set_wasm_store
- parser_take_wasm_store
- point_edit
- predicates_iter
- query_capture_count
- query_capture_name_for_id
- query_capture_quantifier_for_id
- query_cursor_delete
- query_cursor_did_exceed_match_limit
- query_cursor_exec
- query_cursor_exec_with_options
- query_cursor_match_limit
- query_cursor_new
- query_cursor_next_capture
- query_cursor_next_match
- query_cursor_remove_match
- query_cursor_set_byte_range
- query_cursor_set_containing_byte_range
- query_cursor_set_containing_point_range
- query_cursor_set_match_limit
- query_cursor_set_max_start_depth
- query_cursor_set_point_range
- query_delete
- query_disable_capture
- query_disable_pattern
- query_end_byte_for_pattern
- query_is_pattern_guaranteed_at_step
- query_is_pattern_non_local
- query_is_pattern_rooted
- query_new
- query_pattern_count
- query_predicates_for_pattern
- query_start_byte_for_pattern
- query_string_count
- query_string_value_for_id
- range_edit
- set_allocator
- set_odin_allocator
- tree_copy
- tree_cursor_copy
- tree_cursor_current_depth
- tree_cursor_current_descendant_index
- tree_cursor_current_field_id
- tree_cursor_current_field_name
- tree_cursor_current_node
- tree_cursor_delete
- tree_cursor_goto_descendant
- tree_cursor_goto_first_child
- tree_cursor_goto_first_child_for_byte
- tree_cursor_goto_first_child_for_point
- tree_cursor_goto_last_child
- tree_cursor_goto_next_sibling
- tree_cursor_goto_parent
- tree_cursor_goto_previous_sibling
- tree_cursor_new
- tree_cursor_reset
- tree_cursor_reset_to
- tree_delete
- tree_edit
- tree_get_changed_ranges
- tree_included_ranges
- tree_language
- tree_print_dot_graph
- tree_root_node
- tree_root_node_with_offset
- wasm_store_delete
- wasm_store_language_count
- wasm_store_load_language
- wasm_store_new
Types
Compat_Allocator ¶
Compat_Allocator :: mem.Compat_Allocator
Decode_Function ¶
This function signature reads one code point from the given string,
returning the number of bytes consumed. It should write the code point
to the code_point pointer, or write -1 if the input is invalid.
Field_Id ¶
Field_Id :: distinct u16
Related Procedures With Parameters
Related Procedures With Returns
File_Input ¶
Related Procedures With Parameters
Input ¶
Input :: struct { payload: rawptr, read: proc "c" (payload: rawptr, byte_index: u32, position: Point, bytes_read: ^u32) -> cstring, encoding: Input_Encoding, decode: Decode_Function, }
Related Procedures With Parameters
Related Procedures With Returns
Input_Edit ¶
Input_Edit :: struct { start_byte: u32, old_end_byte: u32, new_end_byte: u32, start_point: Point, old_end_point: Point, new_end_point: Point, }
Related Procedures With Parameters
Input_Encoding ¶
Input_Encoding :: enum i32 { UTF8 = 0, UTF16LE, UTF16BE, Custom, }
Related Procedures With Parameters
Language ¶
Language :: distinct rawptr
Opaque pointer.
Related Procedures With Parameters
- language_abi_version
- language_copy
- language_delete
- language_field_count
- language_field_id_for_name
- language_field_name_for_id
- language_is_wasm
- language_metadata
- language_name
- language_next_state
- language_state_count
- language_subtypes
- language_supertypes
- language_symbol_count
- language_symbol_for_name
- language_symbol_name
- language_symbol_type
- lookahead_iterator_new
- lookahead_iterator_reset
- parser_set_language
- query_new
Related Procedures With Returns
Language_Metadata ¶
* * The metadata associated with a language. * * Currently, this metadata can be used to check the [Semantic Version](https://semver.org/) * of the language. This version information should be used to signal if a given parser might * be incompatible with existing queries when upgrading between major versions, or minor versions * if it's in zerover.
Related Procedures With Returns
Log_Type ¶
Log_Type :: enum i32 { Parse = 0, Lex, }
Logger ¶
Logger :: struct { payload: rawptr, log: proc "c" (payload: rawptr, log_type: Log_Type, buffer: cstring), }
Related Procedures With Parameters
Related Procedures With Returns
Lookahead_Iterator ¶
Lookahead_Iterator :: distinct rawptr
Opaque pointer.
Related Procedures With Parameters
Related Procedures With Returns
Node ¶
Related Procedures With Parameters
- node_child
- node_child_by_field_id
- node_child_by_field_name
- node_child_count
- node_child_with_descendant
- node_descendant_count
- node_descendant_for_byte_range
- node_descendant_for_point_range
- node_edit
- node_end_byte
- node_end_point
- node_eq
- node_field_name_for_child
- node_field_name_for_named_child
- node_first_child_for_byte
- node_first_named_child_for_byte
- node_grammar_symbol
- node_grammar_type
- node_has_changes
- node_has_error
- node_is_error
- node_is_extra
- node_is_missing
- node_is_named
- node_is_null
- node_language
- node_named_child
- node_named_child_count
- node_named_descendant_for_byte_range
- node_named_descendant_for_point_range
- node_next_named_sibling
- node_next_parse_state
- node_next_sibling
- node_parent
- node_parse_state
- node_prev_named_sibling
- node_prev_sibling
- node_start_byte
- node_start_point
- node_string
- node_symbol
- node_text
- node_type
- query_cursor_exec
- query_cursor_exec_with_options
- tree_cursor_new
- tree_cursor_reset
- node_descendant_for_range (procedure groups)
- node_named_descendant_for_range (procedure groups)
Related Procedures With Returns
Parse_Options ¶
Parse_Options :: struct { payload: rawptr, progress_callback: proc(state: ^Parse_State) -> bool, }
Related Procedures With Parameters
Parser ¶
Parser :: distinct rawptr
Opaque pointer.
Related Procedures With Parameters
- parser_delete
- parser_included_ranges
- parser_language
- parser_logger
- parser_parse
- parser_parse_string
- parser_parse_string_encoding
- parser_parse_with_options
- parser_print_dot_graphs
- parser_reset
- parser_set_included_ranges
- parser_set_language
- parser_set_logger
- parser_set_odin_logger
- parser_set_wasm_store
- parser_take_wasm_store
Related Procedures With Returns
Point ¶
Related Procedures With Parameters
- node_descendant_for_point_range
- node_named_descendant_for_point_range
- point_edit
- query_cursor_set_containing_point_range
- query_cursor_set_point_range
- tree_cursor_goto_first_child_for_point
- tree_root_node_with_offset
- node_descendant_for_range (procedure groups)
- node_named_descendant_for_range (procedure groups)
- query_cursor_set_range (procedure groups)
- tree_cursor_goto_first_child_for (procedure groups)
Related Procedures With Returns
Quantifier ¶
Quantifier :: enum i32 { Zero = 0, Zero_Or_One, Zero_Or_More, One, One_Or_More, }
Related Procedures With Returns
Query ¶
Query :: distinct rawptr
Opaque pointer.
Related Procedures With Parameters
- query_capture_count
- query_capture_name_for_id
- query_capture_quantifier_for_id
- query_cursor_exec
- query_cursor_exec_with_options
- query_delete
- query_disable_capture
- query_disable_pattern
- query_end_byte_for_pattern
- query_is_pattern_guaranteed_at_step
- query_is_pattern_non_local
- query_is_pattern_rooted
- query_pattern_count
- query_predicates_for_pattern
- query_start_byte_for_pattern
- query_string_count
- query_string_value_for_id
Related Procedures With Returns
Query_Cursor ¶
Query_Cursor :: distinct rawptr
Opaque pointer.
Related Procedures With Parameters
- query_cursor_delete
- query_cursor_did_exceed_match_limit
- query_cursor_exec
- query_cursor_exec_with_options
- query_cursor_match_limit
- query_cursor_next_capture
- query_cursor_next_match
- query_cursor_remove_match
- query_cursor_set_byte_range
- query_cursor_set_containing_byte_range
- query_cursor_set_containing_point_range
- query_cursor_set_match_limit
- query_cursor_set_max_start_depth
- query_cursor_set_point_range
- query_cursor_set_range (procedure groups)
Related Procedures With Returns
Query_Cursor_Options ¶
Query_Cursor_Options :: struct { payload: rawptr, progress_callback: proc(state: ^Query_Cursor_State) -> bool, }
Related Procedures With Parameters
Query_Error ¶
Query_Error :: enum i32 { None = 0, Syntax, Node_Type, Field, Capture, Structure, Language, }
Related Procedures With Returns
Query_Match ¶
Query_Match :: struct { id: u32, pattern_index: u16, capture_count: u16, captures: [^]Query_Capture, }
Related Procedures With Returns
Query_Predicate_Step ¶
Query_Predicate_Step :: struct { type: Query_Predicate_Step_Type, value_id: u32, }
Query_Predicate_Step_Type ¶
Query_Predicate_Step_Type :: enum i32 { Done = 0, Capture, String, }
Range ¶
Related Procedures With Parameters
State_Id ¶
State_Id :: distinct u16
Related Procedures With Parameters
Related Procedures With Returns
Symbol_Type ¶
Symbol_Type :: enum i32 { Regular = 0, Anonymous, Supertype, Auxiliary, }
Related Procedures With Returns
Tree_Cursor ¶
Related Procedures With Parameters
- tree_cursor_copy
- tree_cursor_current_depth
- tree_cursor_current_descendant_index
- tree_cursor_current_field_id
- tree_cursor_current_field_name
- tree_cursor_current_node
- tree_cursor_delete
- tree_cursor_goto_descendant
- tree_cursor_goto_first_child
- tree_cursor_goto_first_child_for_byte
- tree_cursor_goto_first_child_for_point
- tree_cursor_goto_last_child
- tree_cursor_goto_next_sibling
- tree_cursor_goto_parent
- tree_cursor_goto_previous_sibling
- tree_cursor_reset
- tree_cursor_reset_to
- tree_cursor_goto_first_child_for (procedure groups)
Related Procedures With Returns
Wasm_Engine ¶
Wasm_Engine :: struct {}
typedef struct wasm_engine_t TSWasmEngine; typedef struct TSWasmStore TSWasmStore;
Related Procedures With Parameters
Wasm_Error ¶
Wasm_Error :: struct { kind: Wasm_Error_Kind, message: cstring, }
Related Procedures With Parameters
Related Procedures With Returns
Wasm_Error_Kind ¶
Wasm_Error_Kind :: enum i32 { None = 0, Parse, Compile, Instantiate, Allocate, }
Wasm_Store ¶
Wasm_Store :: struct {}
Related Procedures With Parameters
Related Procedures With Returns
Constants
LANGUAGE_VERSION ¶
LANGUAGE_VERSION :: 15
* * The latest ABI version that is supported by the current version of the * library. When Languages are generated by the Tree-sitter CLI, they are * assigned an ABI version number that corresponds to the current CLI version. * The Tree-sitter library is generally backwards-compatible with languages * generated using older CLI versions, but is not forwards-compatible.
MIN_COMPATIBLE_LANGUAGE_VERSION ¶
MIN_COMPATIBLE_LANGUAGE_VERSION :: 13
* * The earliest ABI version that is supported by the current version of the * library.
Variables
This section is empty.
Procedures
file_input ¶
file_input :: proc(fi: ^File_Input, fh: ^os.File, buf: []u8, encoding: Input_Encoding = .UTF8) -> Input {…}
language_abi_version ¶
Get the ABI version number for this language. This version number is used to ensure that languages were generated by a compatible version of Tree-sitter.
See also parser_set_language.
language_copy ¶
Get another reference to the given language.
language_delete ¶
language_delete :: proc "c" (self: Language) ---
Free any dynamically-allocated resources for this language, if this is the last reference.
language_field_count ¶
Get the number of distinct field names in the language.
language_field_id_for_name ¶
Get the numerical id for the given field name string.
language_field_name_for_id ¶
Get the field name string for the given numerical id.
language_is_wasm ¶
Check if the language came from a Wasm module. If so, then in order to use this language with a Parser, that parser must have a Wasm store assigned.
language_metadata ¶
language_metadata :: proc "c" (self: Language) -> Language_Metadata ---
Get the metadata for this language. This information is generated by the
CLI, and relies on the language author providing the correct metadata in
the language's tree-sitter.json file.
See also Language_Metadata.
language_name ¶
Get the name of this language. This returns nil in older parsers.
language_next_state ¶
Get the next parse state. Combine this with lookahead iterators to generate
completion suggestions or valid symbols in error nodes. Use
[node_grammar_symbol] for valid symbols.
language_state_count ¶
Get the number of valid states in this language.
language_subtypes ¶
Get a list of all subtype symbol ids for a given supertype symbol.
See language_supertypes for fetching all supertype symbols.
language_supertypes ¶
Get a list of all supertype symbols for the language.
language_symbol_count ¶
Get the number of distinct node types in the language.
language_symbol_for_name ¶
language_symbol_for_name :: proc(self: Language, string: untyped string, is_named: bool) -> Symbol {…}
Get the numerical id for the given node type string.
language_symbol_name ¶
Get a node type string for the given numerical id.
language_symbol_type ¶
language_symbol_type :: proc "c" (self: Language, symbol: Symbol) -> Symbol_Type ---
Check whether the given node type id belongs to named nodes, anonymous nodes, or a hidden nodes.
See also [node_is_named]. Hidden nodes are never returned from the API.
lookahead_iterator_current_symbol ¶
lookahead_iterator_current_symbol :: proc "c" (self: Lookahead_Iterator) -> Symbol ---
Get the current symbol of the lookahead iterator;
lookahead_iterator_current_symbol_name ¶
lookahead_iterator_current_symbol_name :: proc "c" (self: Lookahead_Iterator) -> cstring ---
Get the current symbol type of the lookahead iterator as a null terminated string.
lookahead_iterator_delete ¶
lookahead_iterator_delete :: proc "c" (self: Lookahead_Iterator) ---
Delete a lookahead iterator freeing all the memory used.
lookahead_iterator_language ¶
lookahead_iterator_language :: proc "c" (self: Lookahead_Iterator) -> Language ---
Get the current language of the lookahead iterator.
lookahead_iterator_new ¶
lookahead_iterator_new :: proc "c" (self: Language, state: State_Id) -> Lookahead_Iterator ---
Create a new lookahead iterator for the given language and parse state.
This returns NULL if state is invalid for the language.
Repeatedly using [lookahead_iterator_next] and
[lookahead_iterator_current_symbol] will generate valid symbols in the
given parse state. Newly created lookahead iterators will contain the ERROR
symbol.
Lookahead iterators can be useful to generate suggestions and improve syntax
error diagnostics. To get symbols valid in an ERROR node, use the lookahead
iterator on its first leaf node state. For MISSING nodes, a lookahead
iterator created on the previous non-extra leaf node may be appropriate.
lookahead_iterator_next ¶
lookahead_iterator_next :: proc "c" (self: Lookahead_Iterator) -> bool ---
Advance the lookahead iterator to the next symbol.
This returns true if there is a new symbol and false otherwise.
lookahead_iterator_reset ¶
lookahead_iterator_reset :: proc "c" (self: Lookahead_Iterator, language: Language, state: State_Id) -> bool ---
Reset the lookahead iterator.
This returns true if the language was set successfully and false
otherwise.
lookahead_iterator_reset_state ¶
lookahead_iterator_reset_state :: proc "c" (self: Lookahead_Iterator, state: State_Id) -> bool ---
Reset the lookahead iterator to another state.
This returns true if the iterator was reset to the given state and false
otherwise.
node_child ¶
Get the node's child at the given index, where zero represents the first child.
node_child_by_field_id ¶
Get the node's child with the given numerical field id.
You can convert a field name to an id using the
[ts_language_field_id_for_name] function.
node_child_by_field_name ¶
Get the node's child with the given field name.
node_child_count ¶
Get the node's number of children.
node_child_with_descendant ¶
Get the node that contains descendant.
Note that this can return descendant itself.
node_descendant_count ¶
Get the node's number of descendants, including one for the node itself.
node_descendant_for_byte_range ¶
Get the smallest node within this node that spans the given range of bytes or (row, column) positions.
Related Procedure Groups
node_descendant_for_point_range ¶
Get the smallest node within this node that spans the given range of bytes or (row, column) positions.
Related Procedure Groups
node_edit ¶
node_edit :: proc "c" (self: ^Node, edit: ^Input_Edit) ---
Edit the node to keep it in-sync with source code that has been edited.
This function is only rarely needed. When you edit a syntax tree with the
[tree_edit] function, all of the nodes that you retrieve from the tree
afterward will already reflect the edit. You only need to use [node_edit]
when you have a [Node] instance that you want to keep and continue to use
after an edit.
node_end_point ¶
Get the node's end position in terms of rows and columns.
node_eq ¶
Check if two nodes are identical.
node_field_name_for_child ¶
Get the field name for node's child at the given index, where zero represents the first child. Returns NULL, if no field is found.
node_field_name_for_named_child ¶
Get the field name for node's named child at the given index, where zero
represents the first named child. Returns nil, if no field is found.
node_first_child_for_byte ¶
Get the node's first child that contains or starts after the given byte offset.
node_first_named_child_for_byte ¶
Get the node's first named child that contains or starts after the given byte offset.
node_grammar_symbol ¶
Get the node's type as a numerical id as it appears in the grammar ignoring
aliases. This should be used in [language_next_state] instead of
[node_symbol].
node_grammar_type ¶
Get the node's type as it appears in the grammar ignoring aliases as a null-terminated string.
node_has_changes ¶
Check if a syntax node has been edited.
node_has_error ¶
Check if the node is a syntax error or contains any syntax errors.
node_is_error ¶
Check if the node is a syntax error.
node_is_extra ¶
Check if the node is extra. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.
node_is_missing ¶
Check if the node is missing. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.
node_is_named ¶
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.
node_is_null ¶
Check if the node is null. Functions like [node_child] and
[node_next_sibling] will return a null node to indicate that no such node
was found.
node_language ¶
Get the node's language.
node_named_child ¶
Get the node's named child at the given index.
See also [ts_node_is_named].
node_named_child_count ¶
Get the node's number of named children.
See also [ts_node_is_named].
node_named_descendant_for_byte_range ¶
Get the smallest named node within this node that spans the given range of bytes or (row, column) positions.
Related Procedure Groups
node_named_descendant_for_point_range ¶
Get the smallest named node within this node that spans the given range of bytes or (row, column) positions.
Related Procedure Groups
node_next_named_sibling ¶
Get the node's next named sibling.
node_next_parse_state ¶
Get the parse state after this node.
node_next_sibling ¶
Get the node's next sibling.
node_parent ¶
Get the node's immediate parent.
Prefer node_child_with_descendant for
iterating over the node's ancestors.
node_parse_state ¶
Get this node's parse state.
node_prev_named_sibling ¶
Get the node's previous named sibling.
node_prev_sibling ¶
Get the node's previous sibling.
node_start_byte ¶
Get the node's start byte.
node_start_point ¶
Get the node's start position in terms of rows and columns.
node_string ¶
Get an S-expression representing the node as a string.
NOTE: This string is allocated with the provided malloc and the caller is responsible for
freeing it using free.
node_symbol ¶
Get the node's type as a numerical id.
node_text ¶
node_text :: proc(self: Node, source: untyped string) -> untyped string {…}
node_type ¶
Get the node's type as a null-terminated string.
parser_delete ¶
parser_delete :: proc "c" (self: Parser) ---
Delete the parser, freeing all of the memory that it used.
parser_included_ranges ¶
Get the ranges of text that the parser will include when parsing.
parser_language ¶
Get the parser's current language.
parser_logger ¶
Get the parser's current logger.
parser_parse ¶
Use the parser to parse some source code and create a syntax tree.
If you are parsing this document for the first time, pass NULL for the
old_tree parameter. Otherwise, if you have already parsed an earlier
version of this document and the document has since been edited, pass the
previous syntax tree so that the unchanged parts of it can be reused.
This will save time and memory. For this to work correctly, you must have
already edited the old syntax tree using the [tree_edit] function in a
way that exactly matches the source code changes.
The [Input] parameter lets you specify how to read the text. It has the
following three fields:
1. [read]: A function to retrieve a chunk of text at a given byte offset
and (row, column) position. The function should return a pointer to the
text and write its length to the [bytes_read] pointer. The parser does
not take ownership of this buffer; it just borrows it until it has
finished reading it. The function should write a zero value to the
[bytes_read] pointer to indicate the end of the document.
2. [payload]: An arbitrary pointer that will be passed to each invocation
of the [read] function.
3. [encoding]: An indication of how the text is encoded. Either
TSInputEncodingUTF8 or TSInputEncodingUTF16.
This function returns a syntax tree on success, and NULL on failure. There
are four possible reasons for failure:
1. The parser does not have a language assigned. Check for this using the
[parser_language] function.
2. Parsing was cancelled due to the progress callback return true. This
callback is passed in parser_parse_with_options inside the Parse_Options
struct.
[read]: Input::read
[payload]: Input::payload
[encoding]: Input::encoding
[bytes_read]: Input::read
parser_parse_string ¶
Use the parser to parse some source code stored in one contiguous buffer.
The other two parameters are the same as in the [parser_parse] function
above.
parser_parse_string_encoding ¶
parser_parse_string_encoding :: proc(self: Parser, string: untyped string, encoding: Input_Encoding, old_tree: Tree = nil) -> Tree {…}
Use the parser to parse some source code stored in one contiguous buffer with
a given encoding. The other parameters work the same as in the
[parser_parse_string] method above. The encoding parameter indicates whether
the text is encoded as UTF8 or UTF16.
parser_parse_with_options ¶
parser_parse_with_options :: proc "c" (self: Parser, old_tree: Tree, input: Input, parse_options: Parse_Options) -> runtime.Maybe($T=Tree) ---
Use the parser to parse some source code and create a syntax tree, with some options.
See parser_parse for more details.
See Parse_Options for more details on the options.
parser_print_dot_graphs ¶
Set the file descriptor to which the parser should write debugging graphs
during parsing. The graphs are formatted in the DOT language. You may want
to pipe these graphs directly to a dot(1) process in order to generate
SVG output. You can turn off this logging by passing a negative fd.
parser_reset ¶
parser_reset :: proc "c" (self: Parser) ---
Instruct the parser to start the next parse from the beginning.
If the parser previously failed because the progress callback, then
by default, it will resume where it left off on the next call to
[parser_parse] or other parsing functions. If you don't want to resume,
and instead intend to use this parser to parse some other document, you must
call [parser_reset] first.
parser_set_included_ranges ¶
set the ranges of text that the parser should include when parsing.
by default, the parser will always include entire documents. this function allows you to parse only a portion of a document but still return a syntax tree whose ranges match up with the document as a whole. you can also pass multiple disjoint ranges.
the second parameter specifies the slice of ranges. the parser does not take ownership of these ranges; it copies the data, so it doesn't matter how these ranges are allocated.
if len(ranges) is zero, then the entire document will be parsed. otherwise,
the given ranges must be ordered from earliest to latest in the document,
and they must not overlap. that is, the following must hold for all:
i < len(ranges) - 1: ranges[i].end_byte <= ranges[i + 1].start_byte
if this requirement is not satisfied, the operation will fail, the ranges
will not be assigned, and this function will return false. on success,
this function returns true
parser_set_language ¶
Set the language that the parser should use for parsing.
Returns a boolean indicating whether or not the language was successfully
assigned. True means assignment succeeded. False means there was a version
mismatch: the language was generated with an incompatible version of the
Tree-sitter CLI. Check the language's ABI version using language_abi_version
and compare it to this library's [LANGUAGE_VERSION] and
[MIN_COMPATIBLE_LANGUAGE_VERSION] constants.
parser_set_logger ¶
Set the logger that a parser should use during parsing.
The parser does not take ownership over the logger payload. If a logger was previously assigned, the caller is responsible for releasing any memory owned by the previous logger.
parser_set_odin_logger ¶
parser_set_odin_logger :: proc(self: Parser, logger: ^runtime.Logger, $level: runtime.Logger_Level) {…}
NOTE: even though there is nothing printed when the log level is higher, tree-sitter still formats all the log messages, this has huge overhead so you should probably only set this if you actually have the log level of it.
parser_set_wasm_store ¶
parser_set_wasm_store :: proc "c" (self: Parser, store: ^Wasm_Store) ---
Assign the given Wasm store to the parser. A parser must have a Wasm store in order to use Wasm languages.
parser_take_wasm_store ¶
parser_take_wasm_store :: proc "c" (self: Parser) -> ^Wasm_Store ---
Remove the parser's current Wasm store and return it. This returns NULL if the parser doesn't have a Wasm store.
point_edit ¶
point_edit :: proc "c" (point: ^Point, point_byte: ^u32, edit: ^Input_Edit) ---
Edit a point to keep it in-sync with source code that has been edited.
This function updates a single point's byte offset and row/column position based on an edit operation. This is useful for editing points without requiring a tree or node instance.
predicates_iter ¶
predicates_iter :: proc(preds: ^[]Query_Predicate_Step) -> ([]Query_Predicate_Step, bool) {…}
Iterates over the predicates by subslicing them split by the .Done type.
query_capture_count ¶
Get the number of patterns, captures, or string literals in the query.
query_capture_name_for_id ¶
Get the name of one of the query's captures, or one of the query's string literals. Each capture and string is associated with a numeric id based on the order that it appeared in the query's source.
query_capture_quantifier_for_id ¶
query_capture_quantifier_for_id :: proc "c" (self: Query, pattern_index: u32, capture_index: u32) -> Quantifier ---
Get the quantifier of the query's captures. Each capture is * associated with a numeric id based on the order that it appeared in the query's source.
query_cursor_delete ¶
query_cursor_delete :: proc "c" (self: Query_Cursor) ---
Delete a query cursor, freeing all of the memory that it used.
query_cursor_did_exceed_match_limit ¶
query_cursor_did_exceed_match_limit :: proc "c" (self: Query_Cursor) -> bool ---
Manage the maximum number of in-progress matches allowed by this query cursor.
Query cursors have an optional maximum capacity for storing lists of in-progress captures. If this capacity is exceeded, then the earliest-starting match will silently be dropped to make room for further matches. This maximum capacity is optional — by default, query cursors allow any number of pending matches, dynamically allocating new space for them as needed as the query is executed.
query_cursor_exec ¶
query_cursor_exec :: proc "c" (self: Query_Cursor, query: Query, node: Node) ---
Start running a given query on a given node.
query_cursor_exec_with_options ¶
query_cursor_exec_with_options :: proc "c" (self: Query_Cursor, query: Query, node: Node, query_options: ^Query_Cursor_Options) ---
Start running a given query on a given node, with some options.
query_cursor_match_limit ¶
query_cursor_match_limit :: proc "c" (self: Query_Cursor) -> u32 ---
Manage the maximum number of in-progress matches allowed by this query cursor.
Query cursors have an optional maximum capacity for storing lists of in-progress captures. If this capacity is exceeded, then the earliest-starting match will silently be dropped to make room for further matches. This maximum capacity is optional — by default, query cursors allow any number of pending matches, dynamically allocating new space for them as needed as the query is executed.
query_cursor_new ¶
query_cursor_new :: proc "c" () -> Query_Cursor ---
Create a new cursor for executing a given query.
The cursor stores the state that is needed to iteratively search
for matches. To use the query cursor, first call [query_cursor_exec]
to start running a given query on a given syntax node. Then, there are
two options for consuming the results of the query:
1. Repeatedly call [query_cursor_next_match] to iterate over all of the
matches in the order that they were found. Each match contains the
index of the pattern that matched, and an array of captures. Because
multiple patterns can match the same set of nodes, one match may contain
captures that appear before some of the captures from a previous match.
2. Repeatedly call [query_cursor_next_capture] to iterate over all of the
individual captures in the order that they appear. This is useful if
don't care about which pattern matched, and just want a single ordered
sequence of captures.
If you don't care about consuming all of the results, you can stop calling
[query_cursor_next_match] or [query_cursor_next_capture] at any point.
You can then start executing another query on another node by calling
[query_cursor_exec] again.
query_cursor_next_capture ¶
query_cursor_next_capture :: proc(self: Query_Cursor) -> (match: Query_Match, capture_index: u32, ok: bool) {…}
Advance to the next capture of the currently running query.
If there is a capture, return it, and its index within the match's capture. Otherwise return false.
query_cursor_next_match ¶
query_cursor_next_match :: proc(self: Query_Cursor) -> (match: Query_Match, ok: bool) {…}
Advance to the next match of the currently running query.
query_cursor_remove_match ¶
query_cursor_remove_match :: proc "c" (self: Query_Cursor, match_id: u32) ---
Advance to the next match of the currently running query.
If there is a match, write it to *match and return true.
Otherwise, return false.
query_cursor_set_byte_range ¶
query_cursor_set_byte_range :: proc "c" (self: Query_Cursor, start_byte, end_byte: u32) -> bool ---
Set the range of bytes in which the query will be executed.
The query cursor will return matches that intersect with the given point range. This means that a match may be returned even if some of its captures fall outside the specified range, as long as at least part of the match overlaps with the range.
For example, if a query pattern matches a node that spans a larger area than the specified range, but part of that node intersects with the range, the entire match will be returned.
This will return false if the start byte is greater than the end byte, otherwise
it will return true.
Related Procedure Groups
query_cursor_set_containing_byte_range ¶
query_cursor_set_containing_byte_range :: proc "c" (self: Query_Cursor, start_byte, end_byte: u32) -> bool ---
Set the byte range within which all matches must be fully contained.
Set the range of bytes in which matches will be searched for. In contrast to
query_cursor_set_byte_range, this will restrict the query cursor to only return
matches where _all_ nodes are _fully_ contained within the given range. Both functions
can be used together, e.g. to search for any matches that intersect line 5000, as
long as they are fully contained within lines 4500-5500
query_cursor_set_containing_point_range ¶
query_cursor_set_containing_point_range :: proc "c" (self: Query_Cursor, start_point, end_point: Point) -> bool ---
Set the point range within which all matches must be fully contained.
Set the range of bytes in which matches will be searched for. In contrast to
ts_query_cursor_set_point_range, this will restrict the query cursor to only return
matches where _all_ nodes are _fully_ contained within the given range. Both functions
can be used together, e.g. to search for any matches that intersect line 5000, as
long as they are fully contained within lines 4500-5500
query_cursor_set_match_limit ¶
query_cursor_set_match_limit :: proc "c" (self: Query_Cursor, limit: u32) ---
Manage the maximum number of in-progress matches allowed by this query cursor.
Query cursors have an optional maximum capacity for storing lists of in-progress captures. If this capacity is exceeded, then the earliest-starting match will silently be dropped to make room for further matches. This maximum capacity is optional — by default, query cursors allow any number of pending matches, dynamically allocating new space for them as needed as the query is executed.
query_cursor_set_max_start_depth ¶
query_cursor_set_max_start_depth :: proc "c" (self: Query_Cursor, max_start_depth: u32) ---
Set the maximum start depth for a query cursor.
This prevents cursors from exploring children nodes at a certain depth. Note if a pattern includes many children, then they will still be checked.
The zero max start depth value can be used as a special behavior and it helps to destructure a subtree by staying on a node and using captures for interested parts. Note that the zero max start depth only limit a search depth for a pattern's root node but other nodes that are parts of the pattern may be searched at any depth what defined by the pattern structure.
Set to max(u32) to remove the maximum start depth.
query_cursor_set_point_range ¶
query_cursor_set_point_range :: proc "c" (self: Query_Cursor, start_point, end_point: Point) -> bool ---
Set the range of (row, column) positions in which the query will be executed.
The query cursor will return matches that intersect with the given point range. This means that a match may be returned even if some of its captures fall outside the specified range, as long as at least part of the match overlaps with the range.
For example, if a query pattern matches a node that spans a larger area than the specified range, but part of that node intersects with the range, the entire match will be returned.
This will return false if the start point is greater than the end point, otherwise
it will return true.
Related Procedure Groups
query_delete ¶
query_delete :: proc "c" (self: Query) ---
Delete a query, freeing all of the memory that it used.
query_disable_capture ¶
query_disable_capture :: proc(self: Query, name: untyped string) {…}
Disable a certain capture within a query.
This prevents the capture from being returned in matches, and also avoids any resource usage associated with recording the capture. Currently, there is no way to undo this.
query_disable_pattern ¶
Disable a certain pattern within a query.
This prevents the pattern from matching and removes most of the overhead associated with the pattern. Currently, there is no way to undo this.
query_end_byte_for_pattern ¶
Get the byte offset where the given pattern ends in the query's source.
This can be useful when combining queries by concatenating their source code strings.
query_is_pattern_guaranteed_at_step ¶
Check if a given pattern is guaranteed to match once a given step is reached. The step is specified by its byte offset in the query's source code.
query_is_pattern_non_local ¶
Check if the given pattern in the query is 'non local'.
A non-local pattern has multiple root nodes and can match within a repeating sequence of nodes, as specified by the grammar. Non-local patterns disable certain optimizations that would otherwise be possible when executing a query on a specific range of a syntax tree.
query_is_pattern_rooted ¶
Check if the given pattern in the query has a single root node.
query_new ¶
query_new :: proc(language: Language, source: untyped string) -> (query: Query, err_offset: u32, err: Query_Error) {…}
Create a new query from a string containing one or more S-expression patterns. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language.
If all of the given patterns are valid, this returns a [TSQuery].
If a pattern is invalid, this returns NULL, and provides two pieces
of information about the problem:
1. The byte offset of the error is returned in err_offset.
2. The type of error is returned in err.
query_pattern_count ¶
Get the number of patterns, captures, or string literals in the query.
query_predicates_for_pattern ¶
query_predicates_for_pattern :: proc(self: Query, pattern_index: u32) -> []Query_Predicate_Step {…}
Get all of the predicates for the given pattern in the query.
The predicates are represented as a single slice of steps. There are three
types of steps in this slice, which correspond to the three legal values for
the type field:
.Capture - Steps with this type represent names of captures.
Their value_id can be used with the [query_capture_name_for_id] function
to obtain the name of the capture.
.String - Steps with this type represent literal strings.
Their value_id can be used with the [query_string_value_for_id] function
to obtain their string value.
.Done - Steps with this type are sentinels that represent the end of an individual predicate.
If a pattern has two predicates, then there will be two with this type in the slice.
query_start_byte_for_pattern ¶
Get the byte offset where the given pattern starts in the query's source.
This can be useful when combining queries by concatenating their source code strings.
query_string_count ¶
Get the number of patterns, captures, or string literals in the query.
range_edit ¶
range_edit :: proc "c" (range: ^Range, edit: ^Input_Edit) ---
Edit a range to keep it in-sync with source code that has been edited.
This function updates a range's start and end positions based on an edit operation. This is useful for editing ranges without requiring a tree or node instance.
set_allocator ¶
set_allocator :: proc "c" (new_malloc: proc "c" (uint) -> rawptr, new_calloc: proc "c" (uint, uint) -> rawptr, new_realloc: proc "c" (rawptr, uint) -> rawptr, new_free: proc "c" (rawptr)) ---
Set the allocation functions used by the library.
By default, Tree-sitter uses the standard libc allocation functions, but aborts the process when an allocation fails. This function lets you supply alternative allocation functions at runtime.
If you pass NULL for any parameter, Tree-sitter will switch back to
its default implementation of that function.
If you call this function after the library has already been used, then you must ensure that either: 1. All the existing objects have been freed. 2. The new allocator shares its state with the old one, so it is capable of freeing memory that was allocated by the old allocator.
set_odin_allocator ¶
set_odin_allocator :: proc(allocator := context.allocator) {…}
Set the allocator used by tree-sitter to one managed by Odin.
NOTE: .Resize in Odin is used for realloc, but Odin's allocators rely on having an old_size
passed through. Tree Sitter does not give this to us though.
WARN: the allocator you give this must not require old_size on resizes. Use the Compat_Allocator in this package!
tree_copy ¶
Create a shallow copy of the syntax tree. This is very fast.
You need to copy a syntax tree in order to use it on more than one thread at a time, as syntax trees are not thread safe.
tree_cursor_copy ¶
tree_cursor_copy :: proc "c" (cursor: ^Tree_Cursor) -> Tree_Cursor ---
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *cursor);
tree_cursor_current_depth ¶
tree_cursor_current_depth :: proc "c" (self: ^Tree_Cursor) -> u32 ---
Get the depth of the cursor's current node relative to the original node that the cursor was constructed with.
tree_cursor_current_descendant_index ¶
tree_cursor_current_descendant_index :: proc "c" (self: ^Tree_Cursor) -> u32 ---
Get the index of the cursor's current node out of all of the descendants of the original node that the cursor was constructed with.
tree_cursor_current_field_id ¶
tree_cursor_current_field_id :: proc "c" (self: ^Tree_Cursor) -> Field_Id ---
Get the field id of the tree cursor's current node.
This returns zero if the current node doesn't have a field.
See also [node_child_by_field_id], [language_field_id_for_name].
tree_cursor_current_field_name ¶
tree_cursor_current_field_name :: proc "c" (self: ^Tree_Cursor) -> cstring ---
Get the field name of the tree cursor's current node.
This returns NULL if the current node doesn't have a field.
See also [node_child_by_field_name].
tree_cursor_current_node ¶
tree_cursor_current_node :: proc "c" (self: ^Tree_Cursor) -> Node ---
Get the tree cursor's current node.
tree_cursor_delete ¶
tree_cursor_delete :: proc "c" (self: ^Tree_Cursor) ---
Delete a tree cursor, freeing all of the memory that it used.
tree_cursor_goto_descendant ¶
tree_cursor_goto_descendant :: proc "c" (self: ^Tree_Cursor, goal_descendant_index: u32) ---
Move the cursor to the node that is the nth descendant of the original node that the cursor was constructed with, where zero represents the original node itself.
tree_cursor_goto_first_child ¶
tree_cursor_goto_first_child :: proc "c" (self: ^Tree_Cursor) -> bool ---
Move the cursor to the first child of its current node.
This returns true if the cursor successfully moved, and returns false
if there were no children.
tree_cursor_goto_first_child_for_byte ¶
tree_cursor_goto_first_child_for_byte :: proc "c" (self: ^Tree_Cursor, goal_byte: u32) -> i64 ---
Move the cursor to the first child of its current node that extends beyond the given byte offset or point.
This returns the index of the child node if one was found, and returns -1 if no such child was found.
Related Procedure Groups
tree_cursor_goto_first_child_for_point ¶
tree_cursor_goto_first_child_for_point :: proc "c" (self: ^Tree_Cursor, goal_point: Point) -> i64 ---
Move the cursor to the first child of its current node that extends beyond the given byte offset or point.
This returns the index of the child node if one was found, and returns -1 if no such child was found.
Related Procedure Groups
tree_cursor_goto_last_child ¶
tree_cursor_goto_last_child :: proc "c" (self: ^Tree_Cursor) -> bool ---
Move the cursor to the last child of its current node.
This returns true if the cursor successfully moved, and returns false if
there were no children.
NOTE: this function may be slower than [tree_cursor_goto_first_child]
because it needs to iterate through all the children to compute the child's
position.
tree_cursor_goto_next_sibling ¶
tree_cursor_goto_next_sibling :: proc "c" (self: ^Tree_Cursor) -> bool ---
Move the cursor to the next sibling of its current node.
This returns true if the cursor successfully moved, and returns false
if there was no next sibling node.
Note that the node the cursor was constructed with is considered the root of the cursor, and the cursor cannot walk outside this node.
tree_cursor_goto_parent ¶
tree_cursor_goto_parent :: proc "c" (self: ^Tree_Cursor) -> bool ---
Move the cursor to the parent of its current node.
This returns true if the cursor successfully moved, and returns false
if there was no parent node (the cursor was already on the root node).
Note that the node the cursor was constructed with is considered the root of the cursor, and the cursor cannot walk outside this node.
tree_cursor_goto_previous_sibling ¶
tree_cursor_goto_previous_sibling :: proc "c" (self: Tree_Cursor) -> bool ---
Move the cursor to the previous sibling of its current node.
This returns true if the cursor successfully moved, and returns false if
there was no previous sibling node.
NOTE: this function may be slower than
[tree_cursor_goto_next_sibling] due to how node positions are stored. In
the worst case, this will need to iterate through all the children up to the
previous sibling node to recalculate its position. Also note that the node the
cursor was constructed with is considered the root of the cursor, and the cursor
cannot walk outside this node.
tree_cursor_new ¶
tree_cursor_new :: proc "c" (node: Node) -> Tree_Cursor ---
Create a new tree cursor starting from the given node.
A tree cursor allows you to walk a syntax tree more efficiently than is
possible using the [Node] functions. It is a mutable object that is always
on a certain syntax node, and can be moved imperatively to different nodes.
Note that the given node is considered the root of the cursor, and the cursor cannot walk outside this node.
tree_cursor_reset ¶
tree_cursor_reset :: proc "c" (self: ^Tree_Cursor, node: Node) ---
Re-initialize a tree cursor to start at the original node that the cursor was constructed with.
tree_cursor_reset_to ¶
tree_cursor_reset_to :: proc "c" (dst: ^Tree_Cursor, src: ^Tree_Cursor) ---
Re-initialize a tree cursor to the same position as another cursor.
Unlike [tree_cursor_reset], this will not lose parent information and
allows reusing already created cursors.
tree_delete ¶
tree_delete :: proc "c" (self: Tree) ---
Delete the syntax tree, freeing all of the memory that it used.
tree_edit ¶
tree_edit :: proc "c" (self: Tree, edit: ^Input_Edit) ---
Edit the syntax tree to keep it in sync with source code that has been edited.
You must describe the edit both in terms of byte offsets and in terms of (row, column) coordinates.
tree_get_changed_ranges ¶
Compare an old edited syntax tree to a new syntax tree representing the same document, returning a slice of ranges whose syntactic structure has changed.
For this to work correctly, the old syntax tree must have been edited such
that its ranges match up to the new tree. Generally, you'll want to call
this function right after calling one of the [parser_parse] functions.
You need to pass the old tree that was passed to parse, as well as the new
tree that was returned from that function.
NOTE: The returned array is allocated using the provided malloc and the caller is responsible
for freeing.
tree_included_ranges ¶
Get the array of included ranges that was used to parse the syntax tree.
NOTE: The returned slice must be freed by the caller.
tree_language ¶
Get the language that was used to parse the syntax tree.
tree_print_dot_graph ¶
Write a DOT graph describing the syntax tree to the given file.
tree_root_node ¶
Get the root node of the syntax tree.
tree_root_node_with_offset ¶
tree_root_node_with_offset :: proc "c" (self: Tree, offset_bytes: u32, offset_extent: Point) -> Node ---
Get the root node of the syntax tree, but with its position shifted forward by the given offset.
wasm_store_delete ¶
wasm_store_delete :: proc "c" (self: ^Wasm_Store) ---
Free the memory associated with the given Wasm store.
wasm_store_language_count ¶
wasm_store_language_count :: proc "c" (self: ^Wasm_Store) -> uint ---
Get the number of languages instantiated in the given Wasm store.
wasm_store_load_language ¶
wasm_store_load_language :: proc(self: ^Wasm_Store, name: cstring, wasm: untyped string) -> (lang: Language, err: Wasm_Error) {…}
Create a language from a buffer of Wasm. The resulting language behaves like any other Tree-sitter language, except that in order to use it with a parser, that parser must have a Wasm store. Note that the language can be used with any Wasm store, it doesn't need to be the same store that was used to originally load it.
wasm_store_new ¶
wasm_store_new :: proc "c" (engine: ^Wasm_Engine, error: ^Wasm_Error) -> ^Wasm_Store ---
Create a Wasm store.
Procedure Groups
node_descendant_for_range ¶
node_descendant_for_range :: proc{ node_descendant_for_byte_range, node_descendant_for_point_range, }
Get the smallest node within this node that spans the given range of bytes or (row, column) positions.
node_named_descendant_for_range ¶
node_named_descendant_for_range :: proc{ node_named_descendant_for_byte_range, node_named_descendant_for_point_range, }
Get the smallest named node within this node that spans the given range of bytes or (row, column) positions.
query_cursor_set_range ¶
query_cursor_set_range :: proc{ query_cursor_set_byte_range, query_cursor_set_point_range, }
tree_cursor_goto_first_child_for ¶
tree_cursor_goto_first_child_for :: proc{ tree_cursor_goto_first_child_for_byte, tree_cursor_goto_first_child_for_point, }
Move the cursor to the first child of its current node that extends beyond the given byte offset or point.
This returns the index of the child node if one was found, and returns -1 if no such child was found.
Source Files
Generation Information
Generated with odin version dev-2026-03 (vendor "odin") Linux_amd64 @ 2026-03-05 20:23:00.760091722 +0000 UTC