Skip to main content

Crate relon_parser

Crate relon_parser 

Source
Expand description

Relon parser.

Two public entry points cover the full surface:

  • parse_document — strict-parse. Returns Result<Node, ParseDocumentError> and rejects any input that doesn’t form a complete document. Use it from the analyzer’s main entry, the evaluator, the formatter, and the CLI — they all want a hard fail on broken input.
  • parse_document_recovering — IDE-facing partial-AST entry. Returns a ParsedDocument (partial AST + diagnostics) that is always populated, even on completely broken input. Use it from completion / hover / goto-def callers that must keep offering features while the user is mid-edit (#, &, @, {a:, …).

Internals:

  • cst / syntax — rowan CST, the single source of truth for what input the parser accepts.
  • ast — typed wrappers over the CST nodes.
  • lower — CST → legacy Node / Expr / TokenKey tree. The legacy tree is still public because the analyzer and evaluator depend on its semantic shape; new consumers should prefer the ast wrappers (cheap, ranged, error-tolerant).

Re-exports§

pub use fast_path::parse_document_fast;
pub use token::*;

Modules§

ast
Typed-AST wrappers over the rowan CST.
cst
Concrete syntax tree (CST) builder over the lossless lex output. P2 of the rowan rewrite — translates the existing winnow grammar into rowan GreenNodes while preserving every source byte (including whitespace and comments) as first-class tokens.
directive
Directive name constants and shape-by-name lookup.
fast_path
v6-fix-D2-I cold-start parser fast-path.
lex
Round-trip lexer for the v2 (rowan-backed) parser.
rewrite
Shared, post-analyze AST pattern recognition for high-level rewrites.
syntax
Concrete syntax tree (CST) foundation built on rowan.
token

Structs§

ParseDiagnostic
One span-bearing diagnostic from a partial parse. Emitted by parse_document_recovering for every CST recovery point plus any sub-tree the lowering walker could not turn into a Node.
ParsedDocument
Result of parse_document_recovering. Always populated — even completely unrecoverable input yields an empty nodes + a non-empty diagnostics list.

Enums§

ParseDocumentError

Functions§

child_nodes
Yield the expression-shaped child nodes of node for AST walkers (analyzer passes, LSP enclosing-scope lookups, …). Decorators, directives, and type hints are intentionally not included — those have their own dedicated walkers that need different semantics.
combine_ranges
Combine two TokenRanges — start from start.start, end from end.end. Used by binary-expression lowering to compute the operand-bounded range.
parse_document
Parse a Relon document into the legacy Node tree.
parse_document_recovering
Parse source into a partial AST + diagnostics. Never returns Err for any byte input — even completely broken sources produce an empty nodes vec + a populated diagnostics list.
parse_leading_comments
Extract leading comments as a single doc string. Walks the byte prefix of source consuming whitespace + // line / /* */ block comments until the first non-trivia byte. Returns the joined doc-comment text (if any) plus the number of bytes consumed — callers use the count to advance their cursor.