Crate oq3_syntax

Source
Expand description

Syntax Tree library used throughout the rust-analyzer.

Properties:

  • easy and fast incremental re-parsing. (Removed for OpenQASM 3, GJL)
  • 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::HasTextName;
pub use crate::syntax_node::OpenQASM3Language;
pub use crate::syntax_node::PreorderWithTokens;
pub use crate::syntax_node::SyntaxElement;
pub use crate::syntax_node::SyntaxNode;
pub use crate::syntax_node::SyntaxToken;
pub use crate::syntax_node::SyntaxTreeBuilder;
pub use crate::ast::SourceFile;

Modules§

ast
Abstract Syntax Tree, layered on top of untyped SyntaxNodes
syntax_node
This module defines Concrete Syntax Tree (CST), used by rust-analyzer.
ted
Primitive tree editor, ed for trees.

Macros§

T
format_to
Appends formatted string to a String.
match_ast
Matches a SyntaxNode against an ast type.

Structs§

AstPtr
Like SyntaxNodePtr, but remembers the type of node.
GreenNode
Internal node in the immutable tree. It has other nodes and tokens as children.
Parse
Parse is the result of the parsing: a syntax tree and a collection of errors.
ParseOrErrors
Same as Parse except that the GreenNode is wrapped in Option. The Option is None if lexer errors were recorded, in which case no parsing was done. In the same case, all errors will be lexer errors. If there are no lexer errors, the parsing was done, and there is a GreenNode. In this case any errors are parser errors.
Preorder
SmolStr
A SmolStr is a string type that has the following properties:
SyntaxError
Represents the result of unsuccessful tokenization, parsing or tree validation.
SyntaxText
TextRange
A range in text, represented as a pair of TextSize.
TextSize
A measure of text length. Also, equivalently, an index into text.
TokenText

Enums§

Direction
NodeOrToken
SyntaxKind
The kind of syntax node, e.g. IDENT, USE_KW, or STRUCT.
TokenAtOffset
There might be zero, one or two leaves at a given offset.
WalkEvent
WalkEvent describes tree walking process.

Traits§

AsString

Functions§

parse_text

Type Aliases§

SyntaxNodePtr
A “pointer” to a SyntaxNode, via location in the source code.