Expand description
Syntax Tree library used throughout the rust-analyzer.
Properties:
- easy and fast incremental re-parsing
- graceful handling of errors
- full-fidelity representation (any text can be precisely represented as a syntax tree)
For more information, see the RFC. Current implementation is inspired by the Swift one.
The most interesting modules here are syntax_node (which defines concrete
syntax tree) and ast (which defines abstract syntax tree on top of the
CST). The actual parser live in a separate parser crate, though the
lexer lives in this crate.
See api_walkthrough test in this file for a quick API tour!
Re-exports§
pub use crate::ast::AstNode;pub use crate::ast::AstToken;pub use crate::ast::SourceFile;pub use rustc_literal_escaper as unescape;
Modules§
- algo
- Collection of assorted algorithms for syntax trees.
- ast
- Abstract Syntax Tree, layered on top of untyped
SyntaxNodes - hacks
- Things which exist to solve practical issues, but which shouldn’t exist.
- syntax_
editor - Syntax Tree editor
- ted
- Primitive tree editor, ed for trees.
- utils
- A set of utils methods to reuse on other abstraction levels
Macros§
- T
- format_
smolstr - Formats arguments to a
SmolStr, potentially without allocating. - match_
ast - Matches a
SyntaxNodeagainst anasttype.
Structs§
- AstPtr
- Like
SyntaxNodePtr, but remembers the type of node. - Green
Node - Internal node in the immutable tree. It has other nodes and tokens as children.
- Parse
Parseis the result of the parsing: a syntax tree and a collection of errors.- Preorder
- SmolStr
- A
SmolStris a string type that has the following properties: - Smol
StrBuilder - A builder that can be used to efficiently build a
SmolStr. - Syntax
Error - Represents the result of unsuccessful tokenization, parsing or tree validation.
- Syntax
Text - Syntax
Tree Builder - Text
Range - A range in text, represented as a pair of
TextSize. - Text
Size - A measure of text length. Also, equivalently, an index into text.
- Token
Text
Enums§
- Direction
- Edition
- Node
OrToken - Rust
Language - Syntax
Kind - The kind of syntax node, e.g.
IDENT,USE_KW, orSTRUCT. - Token
AtOffset - There might be zero, one or two leaves at a given offset.
- Walk
Event WalkEventdescribes tree walking process.
Traits§
- ToSmol
Str - Convert value to
SmolStrusingfmt::Display, potentially without allocating.
Type Aliases§
- Preorder
With Tokens - Syntax
Element - Syntax
Element Children - Syntax
Node - Syntax
Node Children - Syntax
Node Ptr - A “pointer” to a
SyntaxNode, via location in the source code. - Syntax
Token