Skip to main content

Crate cabalist_parser

Crate cabalist_parser 

Source
Expand description

§cabalist-parser

A Rust library that parses .cabal files into a concrete syntax tree (CST), preserving every byte of the original source: whitespace, comments, blank lines, indentation style. The CST can be rendered back to text with byte-identical round-tripping when no edits have been made.

The parser maintains two representations:

  • CST (Concrete Syntax Tree): A flat-arena tree that captures every byte of the source. This is what gets mutated during edits and rendered back to text.

  • AST (Abstract Syntax Tree): A typed, ergonomic view derived from the CST for querying and validation. (Implemented in a separate module.)

§Quick start

use cabalist_parser::parse;

let source = "cabal-version: 3.0\nname: my-package\nversion: 0.1.0.0\n";
let result = parse(source);

// No diagnostics for a valid file.
assert!(result.diagnostics.is_empty());

// Round-trip: render produces the original source.
assert_eq!(result.cst.render(), source);

Re-exports§

pub use ast::CabalFile;
pub use ast::Dependency;
pub use ast::Version;
pub use ast::VersionRange;
pub use cst::CabalCst;
pub use cst::CstNode;
pub use cst::CstNodeKind;
pub use diagnostic::Diagnostic;
pub use diagnostic::Severity;
pub use edit::EditBatch;
pub use edit::ListStyle;
pub use edit::TextEdit;
pub use parse::ParseResult;
pub use span::NodeId;
pub use span::Span;
pub use validate::validate;

Modules§

ast
Typed abstract syntax tree derived from the CST. Abstract Syntax Tree (AST) for .cabal files.
cst
Concrete syntax tree with byte-identical round-trip fidelity. Concrete Syntax Tree (CST) for .cabal files.
diagnostic
Parser diagnostics (errors and warnings). Diagnostics emitted during parsing.
edit
CST mutation operations (add, remove, update fields). Edit engine for surgical CST mutations that preserve formatting.
lexer
Lexer that tokenizes .cabal source into CST nodes. Hand-written lexer for .cabal files.
parse
Parser that builds a CST from source text. Hand-written recursive descent parser for .cabal files.
span
Byte spans and node identifiers. Byte-offset spans and node identifiers for the CST arena.
validate
Structural validation of parsed .cabal files. Validation of a parsed .cabal file against the Cabal specification.

Functions§

parse
Parse a .cabal source string into a ParseResult containing the CST and any diagnostics.