mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-10 08:10:21 -08:00
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html: Update. * admin/notes/tree-sitter/html-manual/Parsing-Program-Source.html: Update. * doc/lispref/modes.texi: Mention the new :level option. * lisp/treesit.el (treesit-font-lock-settings): Update docstring. (treesit-font-lock-rules): Support :level. Relayout the let form. (treesit-font-lock-fontify-region): Support :level.
129 lines
6.4 KiB
HTML
129 lines
6.4 KiB
HTML
<!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>Parsing Program Source (GNU Emacs Lisp Reference Manual)</title>
|
|
|
|
<meta name="description" content="Parsing Program Source (GNU Emacs Lisp Reference Manual)">
|
|
<meta name="keywords" content="Parsing Program Source (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="index.html" rel="up" title="Top">
|
|
<link href="Abbrevs.html" rel="next" title="Abbrevs">
|
|
<link href="Syntax-Tables.html" rel="prev" title="Syntax Tables">
|
|
<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="chapter" id="Parsing-Program-Source">
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Abbrevs.html" accesskey="n" rel="next">Abbrevs and Abbrev Expansion</a>, Previous: <a href="Syntax-Tables.html" accesskey="p" rel="prev">Syntax Tables</a>, Up: <a href="index.html" accesskey="u" rel="up">Emacs Lisp</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="Parsing-Program-Source-1"></span><h2 class="chapter">37 Parsing Program Source</h2>
|
|
|
|
<p>Emacs provides various ways to parse program source text and produce a
|
|
<em>syntax tree</em>. In a syntax tree, text is no longer a
|
|
one-dimensional stream but a structured tree of nodes, where each node
|
|
representing a piece of text. Thus a syntax tree can enable
|
|
interesting features like precise fontification, indentation,
|
|
navigation, structured editing, etc.
|
|
</p>
|
|
<p>Emacs has a simple facility for parsing balanced expressions
|
|
(see <a href="Parsing-Expressions.html">Parsing Expressions</a>). There is also SMIE library for generic
|
|
navigation and indentation (see <a href="SMIE.html">Simple Minded Indentation Engine</a>).
|
|
</p>
|
|
<p>Emacs also provides integration with tree-sitter library
|
|
(<a href="https://tree-sitter.github.io/tree-sitter">https://tree-sitter.github.io/tree-sitter</a>) if compiled with
|
|
it. The tree-sitter library implements an incremental parser and has
|
|
support from a wide range of programming languages.
|
|
</p>
|
|
<dl class="def">
|
|
<dt id="index-treesit_002davailable_002dp"><span class="category">Function: </span><span><strong>treesit-available-p</strong><a href='#index-treesit_002davailable_002dp' class='copiable-anchor'> ¶</a></span></dt>
|
|
<dd><p>This function returns non-nil if tree-sitter features are available
|
|
for this Emacs instance.
|
|
</p></dd></dl>
|
|
|
|
<p>For tree-sitter integration with existing Emacs features,
|
|
see <a href="Parser_002dbased-Font-Lock.html">Parser-based Font Lock</a>, <a href="Parser_002dbased-Indentation.html">Parser-based Indentation</a>, and
|
|
<a href="List-Motion.html">Moving over Balanced Expressions</a>.
|
|
</p>
|
|
<p>About naming convention: use “tree-sitter” when referring to it as a
|
|
noun, like <code>python-use-tree-sitter</code>, but use “treesit” for
|
|
prefixes, like <code>python-treesit-indent-function</code>.
|
|
</p>
|
|
<p>To access the syntax tree of the text in a buffer, we need to first
|
|
load a language definition and create a parser with it. Next, we can
|
|
query the parser for specific nodes in the syntax tree. Then, we can
|
|
access various information about the node, and we can pattern-match a
|
|
node with a powerful syntax. Finally, we explain how to work with
|
|
source files that mixes multiple languages. The following sections
|
|
explain how to do each of the tasks in detail.
|
|
</p>
|
|
|
|
<ul class="section-toc">
|
|
<li><a href="Language-Definitions.html" accesskey="1">Tree-sitter Language Definitions</a></li>
|
|
<li><a href="Using-Parser.html" accesskey="2">Using Tree-sitter Parser</a></li>
|
|
<li><a href="Retrieving-Node.html" accesskey="3">Retrieving Node</a></li>
|
|
<li><a href="Accessing-Node.html" accesskey="4">Accessing Node Information</a></li>
|
|
<li><a href="Pattern-Matching.html" accesskey="5">Pattern Matching Tree-sitter Nodes</a></li>
|
|
<li><a href="Multiple-Languages.html" accesskey="6">Parsing Text in Multiple Languages</a></li>
|
|
<li><a href="Tree_002dsitter-C-API.html" accesskey="7">Tree-sitter C API Correspondence</a></li>
|
|
</ul>
|
|
</div>
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="Abbrevs.html">Abbrevs and Abbrev Expansion</a>, Previous: <a href="Syntax-Tables.html">Syntax Tables</a>, Up: <a href="index.html">Emacs Lisp</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>
|