Expand description
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
use elm_ast::{parse, print};
let source = r#"
module Main exposing (..)
add : Int -> Int -> Int
add x y =
x + y
"#;
let module = parse(source).expect("valid Elm source parses");
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 trait for immutable traversal |
visit-mut | VisitMut for in-place mutation |
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, Pattern,
TypeAnnotation,
Declaration, Import,
ModuleHeader.
Re-exports§
pub use file::ElmModule;pub use lexer::Lexer;pub use node::Spanned;pub use span::Position;pub use span::Span;pub use token::Token;pub use parse::parse;pub use parse::parse_recovering;pub use print::pretty_print;pub use print::pretty_print_converged;pub use print::print;
Modules§
- builder
- Builder helpers for constructing Elm AST nodes programmatically.
- comment
- declaration
- display
Displayimplementations for AST types.- exposing
- expr
- file
- fold
- Owned transformation trait for rewriting Elm ASTs.
- ident
- import
- lexer
- literal
- module_
header - node
- operator
- parse
- pattern
- Elm pretty-printer.
- span
- token
- type_
annotation - visit
- Immutable visitor trait for traversing Elm ASTs.
- visit_
mut - Mutable visitor trait for in-place AST transformation.