elm_ast/lib.rs
1//! A [`syn`]-quality Rust library for parsing and constructing Elm 0.19.1 ASTs.
2//!
3//! `elm-ast-rs` provides a complete, strongly-typed representation of Elm source
4//! code as a Rust AST, along with a parser, pretty-printer, and visitor/fold
5//! traits for traversal and transformation.
6//!
7//! # Quick start
8//!
9//! ```rust
10//! use elm_ast::{parse, print};
11//!
12//! let source = r#"
13//! module Main exposing (..)
14//!
15//! add : Int -> Int -> Int
16//! add x y =
17//! x + y
18//! "#;
19//!
20//! let module = parse(source).expect("valid Elm source parses");
21//! assert_eq!(module.declarations.len(), 1);
22//!
23//! let output = print(&module);
24//! assert!(output.contains("add x y"));
25//! ```
26//!
27//! # Features
28//!
29//! All features are enabled by default via `full`. Disable `default-features`
30//! and pick what you need to reduce compile times.
31//!
32//! | Feature | Description |
33//! |-----------|-----------------------------------------------------|
34//! | `full` | Enables all features below (default) |
35//! | `parsing` | [`parse()`] and [`parse_recovering()`] functions |
36//! | `printing`| [`print()`], `Display` impls, `Printer` struct |
37//! | `visit` | [`Visit`](visit::Visit) trait for immutable traversal |
38//! | `visit-mut`| [`VisitMut`](visit_mut::VisitMut) for in-place mutation |
39//! | `fold` | [`Fold`](fold::Fold) for owned transformation |
40//! | `serde` | `Serialize`/`Deserialize` on all AST types |
41//! | `wasm` | WASM bindings via `wasm-bindgen` |
42//!
43//! # AST overview
44//!
45//! The root type is [`ElmModule`], representing a complete `.elm` file. Every
46//! AST node is wrapped in [`Spanned<T>`], which carries source location info
47//! ([`Span`]) alongside the value.
48//!
49//! Key types: [`Expr`](expr::Expr), [`Pattern`](pattern::Pattern),
50//! [`TypeAnnotation`](type_annotation::TypeAnnotation),
51//! [`Declaration`](declaration::Declaration), [`Import`](import::Import),
52//! [`ModuleHeader`](module_header::ModuleHeader).
53//!
54//! [`syn`]: https://docs.rs/syn
55
56// ── Core types (always available) ────────────────────────────────────
57pub mod builder;
58pub mod comment;
59pub mod declaration;
60pub mod exposing;
61pub mod expr;
62pub mod file;
63pub mod ident;
64pub mod import;
65pub mod lexer;
66pub mod literal;
67pub mod module_header;
68pub mod node;
69pub mod operator;
70pub mod pattern;
71pub mod span;
72pub mod token;
73pub mod type_annotation;
74
75// ── Feature-gated modules ───────────────────────────────────────────
76#[cfg(feature = "printing")]
77pub mod display;
78#[cfg(feature = "fold")]
79pub mod fold;
80#[cfg(feature = "parsing")]
81pub mod parse;
82#[cfg(feature = "printing")]
83pub mod print;
84#[cfg(feature = "visit")]
85pub mod visit;
86#[cfg(feature = "visit-mut")]
87pub mod visit_mut;
88#[cfg(feature = "wasm")]
89pub mod wasm;
90
91// ── Re-exports ──────────────────────────────────────────────────────
92pub use file::ElmModule;
93pub use lexer::Lexer;
94pub use node::Spanned;
95pub use span::{Position, Span};
96pub use token::Token;
97
98#[cfg(feature = "parsing")]
99pub use parse::parse;
100#[cfg(feature = "parsing")]
101pub use parse::parse_recovering;
102#[cfg(feature = "printing")]
103pub use print::pretty_print;
104#[cfg(feature = "printing")]
105pub use print::pretty_print_converged;
106#[cfg(feature = "printing")]
107pub use print::print;