You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/emacs-tree-sitter.org
+18-7Lines changed: 18 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -562,7 +562,11 @@ For more details, see Tree-sitter's documentation:
562
562
:EXPORT_FILE_NAME: inspecting
563
563
:END:
564
564
565
-
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 [[*Walking][traverse]] this structure, but does not support modifying it directly (for the purposes of source code transformation or generation).
565
+
{{% notice info %}}
566
+
If your code works with a large number of nodes, consider using the [[*Walking][traversal APIs]], which are more efficient.
567
+
{{% /notice %}}
568
+
569
+
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).
566
570
567
571
- ~tsc-root-node~ /~tree~/ :: Get the root node of a syntax tree.
568
572
- ~tsc-changed-ranges~ /~old-tree new-tree~/ :: Compare an edited old syntax tree to a newly parsed one. It is typically used in ~tree-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]~/.
@@ -631,10 +635,7 @@ As described in the previous section, the ~-named-~ variants of the functions i
631
635
:END:
632
636
Tree-walking functions enable efficient traversal of the syntax tree.
633
637
634
-
*** Traversing All Descendant Nodes
635
-
These functions are high-level APIs that allow traversing the syntax tree in depth-first pre-order.
636
-
637
-
When dealing with a large number of nodes, working with node objects creates a huge pressure on the garbage collector. For better performance, it's advisable to extract and work with individual node properties. The constant ~tsc-valid-node-props~ holds the list of all available property names.
638
+
When dealing with a large number of nodes, working with node objects creates a huge pressure on the garbage collector. For better performance, it's advisable to extract and work with individual node properties. The constant ~tsc-valid-node-props~ holds the list of all available property names:
638
639
# TODO: Make :exports results work with ox-hugo.
639
640
#+begin_src emacs-lisp
640
641
'(:type
@@ -645,6 +646,12 @@ When dealing with a large number of nodes, working with node objects creates a h
645
646
:start-point :end-point
646
647
:range :byte-range)
647
648
#+end_src
649
+
{{% notice note %}}
650
+
Functions that accept a vector of property names can also accept a single property name, in which case only that property is returned/yielded, instead of a vector of properties.
651
+
{{% /notice %}}
652
+
653
+
*** Traversing All Descendant Nodes
654
+
These functions are high-level APIs that allow traversing the syntax tree in depth-first pre-order.
648
655
649
656
- ~tsc-traverse-do~ /~(vars tree-or-node) body~/ :: Evaluate ~body~ with ~vars~ bound to corresponding properties of each traversed node.
650
657
#+begin_src emacs-lisp
@@ -683,8 +690,12 @@ These functions are the low-level APIs that allow walking through the syntax tre
683
690
- ~tsc-goto-next-sibling~ /~cursor~/ :: Attempt to move the cursor to the parent node, the first child node, or the next sibling node. This function returns t if the move was successful, nil if the move is invalid.
684
691
- ~tsc-goto-first-child-for-position~ /~cursor pos~/ :: Attempt to move the cursor to the first child node that extends beyond the given position. This function returns the index of the child node found, nil otherwise.
685
692
- ~tsc-reset-cursor~ /~cursor node~/ :: Re-initialize the cursor to start on a different node.
686
-
- ~tsc-current-node~ /~cursor~/ :: Get the node that the cursor is currently on.
687
-
- ~tsc-current-field~ /~cursor~/ :: Get the field name (as a keyword) associated with the current node.
693
+
- ~tsc-current-node~ /~cursor [props] [output]~/ :: Get the node that the cursor is currently on. If ~props~ is a vector of property names, return a vector containing the node's corresponding properties. If ~output~ is also non-nil, it must be a vector of the same length, where the properties will be written into.
694
+
- ~tsc-current-field~ /~cursor~/ :: Get the field name (as a keyword) associated with the current node. This is equivalent to:
0 commit comments