mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 02:39:32 +00:00
19 lines
No EOL
15 KiB
HTML
19 lines
No EOL
15 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Syntax Tree library used throughout the rust-analyzer."><title>syntax - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-1a91846b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="syntax" data-themes="" data-resource-suffix="" data-rustdoc-version="1.88.0 (6b00bc388 2025-06-23)" data-channel="1.88.0" data-search-js="search-f7877310.js" data-settings-js="settings-5514c975.js" ><script src="../static.files/storage-4e99c027.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-7ef8a74a.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../syntax/index.html">syntax</a><span class="version">0.0.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>syntax</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/syntax/lib.rs.html#1-400">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Syntax Tree library used throughout the rust-analyzer.</p>
|
||
<p>Properties:</p>
|
||
<ul>
|
||
<li>easy and fast incremental re-parsing</li>
|
||
<li>graceful handling of errors</li>
|
||
<li>full-fidelity representation (<em>any</em> text can be precisely represented as
|
||
a syntax tree)</li>
|
||
</ul>
|
||
<p>For more information, see the <a href="https://github.com/rust-lang/rfcs/pull/2256">RFC</a>. Current implementation is inspired by
|
||
the <a href="https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md">Swift</a> one.</p>
|
||
<p>The most interesting modules here are <code>syntax_node</code> (which defines concrete
|
||
syntax tree) and <code>ast</code> (which defines abstract syntax tree on top of the
|
||
CST). The actual parser live in a separate <code>parser</code> crate, though the
|
||
lexer lives in this crate.</p>
|
||
<p>See <code>api_walkthrough</code> test in this file for a quick API tour!</p>
|
||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><dl class="item-table reexports"><dt id="reexport.AstNode"><code>pub use crate::ast::<a class="trait" href="ast/trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a>;</code></dt><dt id="reexport.AstToken"><code>pub use crate::ast::<a class="trait" href="ast/trait.AstToken.html" title="trait syntax::ast::AstToken">AstToken</a>;</code></dt><dt id="reexport.SourceFile"><code>pub use crate::ast::<a class="struct" href="ast/struct.SourceFile.html" title="struct syntax::ast::SourceFile">SourceFile</a>;</code></dt><dt id="reexport.unescape"><code>pub use rustc_literal_escaper as unescape;</code></dt></dl><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="algo/index.html" title="mod syntax::algo">algo</a></dt><dd>Collection of assorted algorithms for syntax trees.</dd><dt><a class="mod" href="ast/index.html" title="mod syntax::ast">ast</a></dt><dd>Abstract Syntax Tree, layered on top of untyped <code>SyntaxNode</code>s</dd><dt><a class="mod" href="hacks/index.html" title="mod syntax::hacks">hacks</a></dt><dd>Things which exist to solve practical issues, but which shouldn’t exist.</dd><dt><a class="mod" href="syntax_editor/index.html" title="mod syntax::syntax_editor">syntax_<wbr>editor</a></dt><dd>Syntax Tree editor</dd><dt><a class="mod" href="ted/index.html" title="mod syntax::ted">ted</a></dt><dd>Primitive tree editor, ed for trees.</dd><dt><a class="mod" href="utils/index.html" title="mod syntax::utils">utils</a></dt><dd>A set of utils methods to reuse on other abstraction levels</dd></dl><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><dl class="item-table"><dt><a class="macro" href="macro.T.html" title="macro syntax::T">T</a></dt><dt><a class="macro" href="macro.format_smolstr.html" title="macro syntax::format_smolstr">format_<wbr>smolstr</a></dt><dd>Formats arguments to a <a href="struct.SmolStr.html" title="struct syntax::SmolStr"><code>SmolStr</code></a>, potentially without allocating.</dd><dt><a class="macro" href="macro.match_ast.html" title="macro syntax::match_ast">match_<wbr>ast</a></dt><dd>Matches a <code>SyntaxNode</code> against an <code>ast</code> type.</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.AstPtr.html" title="struct syntax::AstPtr">AstPtr</a></dt><dd>Like <code>SyntaxNodePtr</code>, but remembers the type of node.</dd><dt><a class="struct" href="struct.GreenNode.html" title="struct syntax::GreenNode">Green<wbr>Node</a></dt><dd>Internal node in the immutable tree.
|
||
It has other nodes and tokens as children.</dd><dt><a class="struct" href="struct.Parse.html" title="struct syntax::Parse">Parse</a></dt><dd><code>Parse</code> is the result of the parsing: a syntax tree and a collection of
|
||
errors.</dd><dt><a class="struct" href="struct.Preorder.html" title="struct syntax::Preorder">Preorder</a></dt><dt><a class="struct" href="struct.SmolStr.html" title="struct syntax::SmolStr">SmolStr</a></dt><dd>A <code>SmolStr</code> is a string type that has the following properties:</dd><dt><a class="struct" href="struct.SmolStrBuilder.html" title="struct syntax::SmolStrBuilder">Smol<wbr>StrBuilder</a></dt><dd>A builder that can be used to efficiently build a <a href="struct.SmolStr.html" title="struct syntax::SmolStr"><code>SmolStr</code></a>.</dd><dt><a class="struct" href="struct.SyntaxError.html" title="struct syntax::SyntaxError">Syntax<wbr>Error</a></dt><dd>Represents the result of unsuccessful tokenization, parsing
|
||
or tree validation.</dd><dt><a class="struct" href="struct.SyntaxText.html" title="struct syntax::SyntaxText">Syntax<wbr>Text</a></dt><dt><a class="struct" href="struct.SyntaxTreeBuilder.html" title="struct syntax::SyntaxTreeBuilder">Syntax<wbr>Tree<wbr>Builder</a></dt><dt><a class="struct" href="struct.TextRange.html" title="struct syntax::TextRange">Text<wbr>Range</a></dt><dd>A range in text, represented as a pair of <a href="struct.TextSize.html" title="struct syntax::TextSize"><code>TextSize</code></a>.</dd><dt><a class="struct" href="struct.TextSize.html" title="struct syntax::TextSize">Text<wbr>Size</a></dt><dd>A measure of text length. Also, equivalently, an index into text.</dd><dt><a class="struct" href="struct.TokenText.html" title="struct syntax::TokenText">Token<wbr>Text</a></dt></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.Direction.html" title="enum syntax::Direction">Direction</a></dt><dt><a class="enum" href="enum.Edition.html" title="enum syntax::Edition">Edition</a></dt><dt><a class="enum" href="enum.NodeOrToken.html" title="enum syntax::NodeOrToken">Node<wbr>OrToken</a></dt><dt><a class="enum" href="enum.RustLanguage.html" title="enum syntax::RustLanguage">Rust<wbr>Language</a></dt><dt><a class="enum" href="enum.SyntaxKind.html" title="enum syntax::SyntaxKind">Syntax<wbr>Kind</a></dt><dd>The kind of syntax node, e.g. <code>IDENT</code>, <code>USE_KW</code>, or <code>STRUCT</code>.</dd><dt><a class="enum" href="enum.TokenAtOffset.html" title="enum syntax::TokenAtOffset">Token<wbr>AtOffset</a></dt><dd>There might be zero, one or two leaves at a given offset.</dd><dt><a class="enum" href="enum.WalkEvent.html" title="enum syntax::WalkEvent">Walk<wbr>Event</a></dt><dd><code>WalkEvent</code> describes tree walking process.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.ToSmolStr.html" title="trait syntax::ToSmolStr">ToSmol<wbr>Str</a></dt><dd>Convert value to <a href="struct.SmolStr.html" title="struct syntax::SmolStr"><code>SmolStr</code></a> using <a href="https://doc.rust-lang.org/1.88.0/core/fmt/trait.Display.html" title="trait core::fmt::Display"><code>fmt::Display</code></a>, potentially without allocating.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.PreorderWithTokens.html" title="type syntax::PreorderWithTokens">Preorder<wbr>With<wbr>Tokens</a></dt><dt><a class="type" href="type.SyntaxElement.html" title="type syntax::SyntaxElement">Syntax<wbr>Element</a></dt><dt><a class="type" href="type.SyntaxElementChildren.html" title="type syntax::SyntaxElementChildren">Syntax<wbr>Element<wbr>Children</a></dt><dt><a class="type" href="type.SyntaxNode.html" title="type syntax::SyntaxNode">Syntax<wbr>Node</a></dt><dt><a class="type" href="type.SyntaxNodeChildren.html" title="type syntax::SyntaxNodeChildren">Syntax<wbr>Node<wbr>Children</a></dt><dt><a class="type" href="type.SyntaxNodePtr.html" title="type syntax::SyntaxNodePtr">Syntax<wbr>Node<wbr>Ptr</a></dt><dd>A “pointer” to a <a href="type.SyntaxNode.html" title="type syntax::SyntaxNode"><code>SyntaxNode</code></a>, via location in the source code.</dd><dt><a class="type" href="type.SyntaxToken.html" title="type syntax::SyntaxToken">Syntax<wbr>Token</a></dt></dl><script type="text/json" id="notable-traits-data">{"Preorder<L>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Preorder.html\" title=\"struct syntax::Preorder\">Preorder</a><L></code></h3><pre><code><div class=\"where\">impl<L> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.Preorder.html\" title=\"struct syntax::Preorder\">Preorder</a><L><div class=\"where\">where\n L: Language,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"enum\" href=\"enum.WalkEvent.html\" title=\"enum syntax::WalkEvent\">WalkEvent</a><SyntaxNode<L>>;</div>","PreorderWithTokens<L>":"<h3>Notable traits for <code>PreorderWithTokens<L></code></h3><pre><code><div class=\"where\">impl<L> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for PreorderWithTokens<L><div class=\"where\">where\n L: Language,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"enum\" href=\"enum.WalkEvent.html\" title=\"enum syntax::WalkEvent\">WalkEvent</a><<a class=\"enum\" href=\"enum.NodeOrToken.html\" title=\"enum syntax::NodeOrToken\">NodeOrToken</a><SyntaxNode<L>, SyntaxToken<L>>>;</div>","SyntaxElementChildren<L>":"<h3>Notable traits for <code>SyntaxElementChildren<L></code></h3><pre><code><div class=\"where\">impl<L> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for SyntaxElementChildren<L><div class=\"where\">where\n L: Language,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"enum\" href=\"enum.NodeOrToken.html\" title=\"enum syntax::NodeOrToken\">NodeOrToken</a><SyntaxNode<L>, SyntaxToken<L>>;</div>","SyntaxNodeChildren<L>":"<h3>Notable traits for <code>SyntaxNodeChildren<L></code></h3><pre><code><div class=\"where\">impl<L> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for SyntaxNodeChildren<L><div class=\"where\">where\n L: Language,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = SyntaxNode<L>;</div>","TokenAtOffset<SyntaxToken<L>>":"<h3>Notable traits for <code><a class=\"enum\" href=\"enum.TokenAtOffset.html\" title=\"enum syntax::TokenAtOffset\">TokenAtOffset</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"enum\" href=\"enum.TokenAtOffset.html\" title=\"enum syntax::TokenAtOffset\">TokenAtOffset</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.88.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = T;</div>"}</script></section></div></main></body></html> |