Module parser

Module parser 

Source
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:

  1. Unknown tokens get wrapped in SyntaxKind::Error nodes and consumed
  2. Missing expected tokens emit a diagnostic but don’t consume (parent may handle)
  3. Recovery sets define “synchronization points” per production
  4. 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§

ParseResult
Parser
Trivia tokens are buffered and flushed when starting a new node.
Token
Zero-copy token: kind + span, text retrieved via token_text when needed.

Enums§

PredicateOp
Predicate operator for node text filtering.
SyntaxKind
All token and node kinds. Tokens first, then nodes, then __LAST sentinel. #[repr(u16)] enables safe transmute in kind_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§

SyntaxNode
Type aliases for Rowan types parameterized by our language.
SyntaxToken