diff options
Diffstat (limited to 'admin/notes/tree-sitter/html-manual/Accessing-Node.html')
-rw-r--r-- | admin/notes/tree-sitter/html-manual/Accessing-Node.html | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/admin/notes/tree-sitter/html-manual/Accessing-Node.html b/admin/notes/tree-sitter/html-manual/Accessing-Node.html new file mode 100644 index 00000000000..00ac63b8339 --- /dev/null +++ b/admin/notes/tree-sitter/html-manual/Accessing-Node.html @@ -0,0 +1,206 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ --> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> +<!-- This is the GNU Emacs Lisp Reference Manual +corresponding to Emacs version 29.0.50. + +Copyright © 1990-1996, 1998-2022 Free Software Foundation, +Inc. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with the +Invariant Sections being "GNU General Public License," with the +Front-Cover Texts being "A GNU Manual," and with the Back-Cover +Texts as in (a) below. A copy of the license is included in the +section entitled "GNU Free Documentation License." + +(a) The FSF's Back-Cover Text is: "You have the freedom to copy and +modify this GNU manual. Buying copies from the FSF supports it in +developing GNU and promoting software freedom." --> +<title>Accessing Node (GNU Emacs Lisp Reference Manual)</title> + +<meta name="description" content="Accessing Node (GNU Emacs Lisp Reference Manual)"> +<meta name="keywords" content="Accessing Node (GNU Emacs Lisp Reference Manual)"> +<meta name="resource-type" content="document"> +<meta name="distribution" content="global"> +<meta name="Generator" content="makeinfo"> +<meta name="viewport" content="width=device-width,initial-scale=1"> + +<link href="index.html" rel="start" title="Top"> +<link href="Index.html" rel="index" title="Index"> +<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> +<link href="Parsing-Program-Source.html" rel="up" title="Parsing Program Source"> +<link href="Pattern-Matching.html" rel="next" title="Pattern Matching"> +<link href="Retrieving-Node.html" rel="prev" title="Retrieving Node"> +<style type="text/css"> +<!-- +a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em} +a.summary-letter {text-decoration: none} +blockquote.indentedblock {margin-right: 0em} +div.display {margin-left: 3.2em} +div.example {margin-left: 3.2em} +kbd {font-style: oblique} +pre.display {font-family: inherit} +pre.format {font-family: inherit} +pre.menu-comment {font-family: serif} +pre.menu-preformatted {font-family: serif} +span.nolinebreak {white-space: nowrap} +span.roman {font-family: initial; font-weight: normal} +span.sansserif {font-family: sans-serif; font-weight: normal} +span:hover a.copiable-anchor {visibility: visible} +ul.no-bullet {list-style: none} +--> +</style> +<link rel="stylesheet" type="text/css" href="./manual.css"> + + +</head> + +<body lang="en"> +<div class="section" id="Accessing-Node"> +<div class="header"> +<p> +Next: <a href="Pattern-Matching.html" accesskey="n" rel="next">Pattern Matching Tree-sitter Nodes</a>, Previous: <a href="Retrieving-Node.html" accesskey="p" rel="prev">Retrieving Node</a>, Up: <a href="Parsing-Program-Source.html" accesskey="u" rel="up">Parsing Program Source</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> +</div> +<hr> +<span id="Accessing-Node-Information"></span><h3 class="section">37.4 Accessing Node Information</h3> + +<p>Before going further, make sure you have read the basic conventions +about tree-sitter nodes in the previous node. +</p> +<span id="Basic-information"></span><h3 class="heading">Basic information</h3> + +<p>Every node is associated with a parser, and that parser is associated +with a buffer. The following functions let you retrieve them. +</p> +<dl class="def"> +<dt id="index-treesit_002dnode_002dparser"><span class="category">Function: </span><span><strong>treesit-node-parser</strong> <em>node</em><a href='#index-treesit_002dnode_002dparser' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function returns <var>node</var>’s associated parser. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dbuffer"><span class="category">Function: </span><span><strong>treesit-node-buffer</strong> <em>node</em><a href='#index-treesit_002dnode_002dbuffer' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function returns <var>node</var>’s parser’s associated buffer. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dlanguage"><span class="category">Function: </span><span><strong>treesit-node-language</strong> <em>node</em><a href='#index-treesit_002dnode_002dlanguage' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function returns <var>node</var>’s parser’s associated language. +</p></dd></dl> + +<p>Each node represents a piece of text in the buffer. Functions below +finds relevant information about that text. +</p> +<dl class="def"> +<dt id="index-treesit_002dnode_002dstart"><span class="category">Function: </span><span><strong>treesit-node-start</strong> <em>node</em><a href='#index-treesit_002dnode_002dstart' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Return the start position of <var>node</var>. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dend"><span class="category">Function: </span><span><strong>treesit-node-end</strong> <em>node</em><a href='#index-treesit_002dnode_002dend' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Return the end position of <var>node</var>. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dtext"><span class="category">Function: </span><span><strong>treesit-node-text</strong> <em>node &optional object</em><a href='#index-treesit_002dnode_002dtext' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Returns the buffer text that <var>node</var> represents. (If <var>node</var> is +retrieved from parsing a string, it will be text from that string.) +</p></dd></dl> + +<p>Here are some basic checks on tree-sitter nodes. +</p> +<dl class="def"> +<dt id="index-treesit_002dnode_002dp"><span class="category">Function: </span><span><strong>treesit-node-p</strong> <em>object</em><a href='#index-treesit_002dnode_002dp' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Checks if <var>object</var> is a tree-sitter syntax node. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002deq"><span class="category">Function: </span><span><strong>treesit-node-eq</strong> <em>node1 node2</em><a href='#index-treesit_002dnode_002deq' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Checks if <var>node1</var> and <var>node2</var> are the same node in a syntax +tree. +</p></dd></dl> + +<span id="Property-information"></span><h3 class="heading">Property information</h3> + +<p>In general, nodes in a concrete syntax tree fall into two categories: +<em>named nodes</em> and <em>anonymous nodes</em>. Whether a node is named +or anonymous is determined by the language definition +(see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>). +</p> +<span id="index-tree_002dsitter-missing-node"></span> +<p>Apart from being named/anonymous, a node can have other properties. A +node can be “missing”: missing nodes are inserted by the parser in +order to recover from certain kinds of syntax errors, i.e., something +should probably be there according to the grammar, but not there. +</p> +<span id="index-tree_002dsitter-extra-node"></span> +<p>A node can be “extra”: extra nodes represent things like comments, +which can appear anywhere in the text. +</p> +<span id="index-tree_002dsitter-node-that-has-changes"></span> +<p>A node “has changes” if the buffer changed since when the node is +retrieved, i.e., outdated. +</p> +<span id="index-tree_002dsitter-node-that-has-error"></span> +<p>A node “has error” if the text it spans contains a syntax error. It +can be the node itself has an error, or one of its +children/grandchildren... has an error. +</p> +<dl class="def"> +<dt id="index-treesit_002dnode_002dcheck"><span class="category">Function: </span><span><strong>treesit-node-check</strong> <em>node property</em><a href='#index-treesit_002dnode_002dcheck' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function checks if <var>node</var> has <var>property</var>. <var>property</var> +can be <code>'named</code>, <code>'missing</code>, <code>'extra</code>, +<code>'has-changes</code>, or <code>'has-error</code>. +</p></dd></dl> + + +<dl class="def"> +<dt id="index-treesit_002dnode_002dtype"><span class="category">Function: </span><span><strong>treesit-node-type</strong> <em>node</em><a href='#index-treesit_002dnode_002dtype' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>Named nodes have “types” (see <a href="Language-Definitions.html#tree_002dsitter-node-type">node type</a>). +For example, a named node can be a <code>string_literal</code> node, where +<code>string_literal</code> is its type. +</p> +<p>This function returns <var>node</var>’s type as a string. +</p></dd></dl> + +<span id="Information-as-a-child-or-parent"></span><h3 class="heading">Information as a child or parent</h3> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dindex"><span class="category">Function: </span><span><strong>treesit-node-index</strong> <em>node &optional named</em><a href='#index-treesit_002dnode_002dindex' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function returns the index of <var>node</var> as a child node of its +parent. If <var>named</var> is non-nil, it only count named nodes +(see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>). +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dfield_002dname"><span class="category">Function: </span><span><strong>treesit-node-field-name</strong> <em>node</em><a href='#index-treesit_002dnode_002dfield_002dname' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>A child of a parent node could have a field name (see <a href="Language-Definitions.html#tree_002dsitter-node-field-name">field name</a>). This function returns the field name +of <var>node</var> as a child of its parent. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dnode_002dfield_002dname_002dfor_002dchild"><span class="category">Function: </span><span><strong>treesit-node-field-name-for-child</strong> <em>node n</em><a href='#index-treesit_002dnode_002dfield_002dname_002dfor_002dchild' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function returns the field name of the <var>n</var>’th child of +<var>node</var>. +</p></dd></dl> + +<dl class="def"> +<dt id="index-treesit_002dchild_002dcount"><span class="category">Function: </span><span><strong>treesit-child-count</strong> <em>node &optional named</em><a href='#index-treesit_002dchild_002dcount' class='copiable-anchor'> ¶</a></span></dt> +<dd><p>This function finds the number of children of <var>node</var>. If +<var>named</var> is non-nil, it only counts named child (see <a href="Language-Definitions.html#tree_002dsitter-named-node">named node</a>). +</p></dd></dl> + +</div> +<hr> +<div class="header"> +<p> +Next: <a href="Pattern-Matching.html">Pattern Matching Tree-sitter Nodes</a>, Previous: <a href="Retrieving-Node.html">Retrieving Node</a>, Up: <a href="Parsing-Program-Source.html">Parsing Program Source</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> +</div> + + + +</body> +</html> |