If your code works with a large number of nodes, consider using the traversal APIs, which are more efficient.
The result of parsing is a syntax tree of the entire source code (string, buffer). It contains syntax nodes that indicate the structure of the source code. Tree-sitter provides APIs to inspect and traverse this structure, but does not support modifying it directly (for the purposes of source code transformation or generation).
tsc-root-node treetsc-changed-ranges old-tree new-treetree-sitter-after-change-functions hook. This function returns a sequence of ranges whose syntactic structure has changed. Each range is a vector in the form of [start-bytepos end-bytepos start-point end-point].
In tree-sitter’s context, point typically means a pair of (line-number . byte-column), instead of its usual meaning of current position. See Data Types.
tsc-tree-to-sexptsc-node-to-sexpFunctions that return a node’s property have the prefix tsc-node-:
tsc-node-typetsc-node-named-pThese less important nodes are called anonymous nodes. Their node types are strings. For example: "if", "else". The more important nodes are call named nodes. Their node types are symbols, corresponding to the named rules that define them in the language’s grammar. For example: identifier, block, if_expression.
In Tree-sitter’s documentation, due to the low-level nature of C and JSON, node types are always represented as strings. Representing named node types as symbols makes it more Lisp-idiomatic, and is more consistent with tree queries.
tsc-node-extra-ptsc-node-error-pERROR.tsc-node-has-error-ptsc-node-missing-ptsc-node-start-bytetsc-node-end-bytetsc-node-start-positiontsc-node-end-positiontsc-node-range[start-bytepos end-bytepos start-point end-point].As described in the previous section, the -named- variants of the functions in this section allow working on the parse tree as if it is an abstract syntax tree.
tsc-get-parent nodetsc-count-children nodetsc-count-named-children nodetsc-get-nth-child node nthtsc-get-nth-named-child node nth(let ((func (tree-sitter-node-at-pos 'function_item)))
(tsc-get-nth-child func 0) ; An "fn" node
(tsc-get-nth-named-child func 0)) ; An 'identifier node
tsc-get-child-by-field node field;; Get name of the current function definition.
(let ((func (tree-sitter-node-at-pos 'function_item)))
(tsc-node-text (tsc-get-child-by-field func :name)))
In Tree-sitter’s documentation, due to the low-level nature of C and JSON, field names are specified as strings. Representing field names as keywords makes it more Lisp-idiomatic.
tsc-get-next-sibling nodetsc-get-prev-sibling nodetsc-get-next-named-sibling nodetsc-get-prev-named-sibling nodetsc-get-descendant-for-position-range node beg endtsc-get-named-descendant-for-position-range node beg end;; Get the syntax node the cursor is on.
(let ((p (point)))
(tsc-get-descendant-for-position-range
(tsc-root-node tree-sitter-tree) p p))