Expand description
Parser infrastructure for the query language.
§Architecture
This parser produces a lossless concrete syntax tree (CST) via Rowan’s green tree builder. Key design decisions borrowed from rust-analyzer, rnix-parser, and taplo:
- Zero-copy parsing: tokens carry spans, text sliced only when building tree nodes
- Trivia buffering: whitespace/comments collected, then attached as leading trivia
- Checkpoint-based wrapping: retroactively wrap nodes for quantifiers
*+? - Explicit recovery sets: per-production sets determine when to bail vs consume diagnostics
§Recovery Strategy
The parser is resilient — it always produces a tree. Recovery follows these rules:
- Unknown tokens get wrapped in
SyntaxKind::Errornodes and consumed - Missing expected tokens emit a diagnostic but don’t consume (parent may handle)
- Recovery sets define “synchronization points” per production
- On recursion limit, remaining input goes into single Error node
However, fuel exhaustion (exec_fuel, recursion_fuel) returns an actual error immediately.
Re-exports§
pub use ast::AltExpr;pub use ast::AltKind;pub use ast::Anchor;pub use ast::AnonymousNode;pub use ast::Branch;pub use ast::CapturedExpr;pub use ast::Def;pub use ast::Expr;pub use ast::FieldExpr;pub use ast::NamedNode;pub use ast::NegatedField;pub use ast::NodePredicate;pub use ast::PredicateValue;pub use ast::QuantifiedExpr;pub use ast::Ref;pub use ast::RegexLiteral;pub use ast::Root;pub use ast::SeqExpr;pub use ast::SeqItem;pub use ast::Type;pub use ast::is_truly_empty_scope;pub use ast::token_src;
Modules§
- ast
- Typed AST wrappers over CST nodes.
Structs§
- Parse
Result - Parser
- Trivia tokens are buffered and flushed when starting a new node.
- Token
- Zero-copy token: kind + span, text retrieved via
token_textwhen needed.
Enums§
- Predicate
Op - Predicate operator for node text filtering.
- Syntax
Kind - All token and node kinds. Tokens first, then nodes, then
__LASTsentinel.#[repr(u16)]enables safe transmute inkind_from_raw.
Functions§
- lex
- Tokenizes source into a vector of span-based tokens.
- token_
text - Retrieves the text slice for a token. O(1) slice into source.
Type Aliases§
- Syntax
Node - Type aliases for Rowan types parameterized by our language.
- Syntax
Token