Skip to main content

Module ast

Module ast 

Source
Expand description

Typed abstract syntax tree derived from the CST. Abstract Syntax Tree (AST) for .cabal files.

The AST is a typed, ergonomic view derived from the CST. It provides structured access to package metadata, components, dependencies, and conditionals. Every AST node carries a NodeId back-reference to the corresponding CST node so that edits can be mapped back to the concrete tree.

The AST does not own the source text: it borrows from the CabalCst’s source string.

§Usage

use cabalist_parser::{parse, ast::derive_ast};

let source = "cabal-version: 3.0\nname: my-pkg\nversion: 0.1.0.0\n";
let result = parse(source);
let ast = derive_ast(&result.cst);
assert_eq!(ast.name, Some("my-pkg"));

Structs§

Benchmark
A benchmark component.
CabalFile
The top-level AST for a parsed .cabal file.
CabalVersion
The cabal-version specification.
CommonStanza
A common stanza.
ComponentFields
Shared fields across all component types (library, executable, etc.).
Conditional
A conditional block (if/elif with optional else) inside a component.
Dependency
A parsed dependency from build-depends.
Executable
An executable component.
Field
A field that was not specifically parsed into a typed representation.
Flag
A flag section.
Library
A library component.
SourceRepository
A source-repository section.
TestSuite
A test-suite component.
Version
A parsed version number like 0.1.0.0.

Enums§

Component
A reference to any component type.
Condition
A parsed condition expression from if/elif blocks.
VersionRange
A version constraint expression.

Functions§

canonicalize_field_name
Canonicalize a .cabal field name to lowercase with hyphens.
derive_ast
Derive a typed AST from a parsed CST.
parse_condition
Parse a condition expression string.
parse_version_range
Parse a version range string.
version_satisfies
Check if a version satisfies a version range (best-effort).