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