daml_parser/lib.rs
1//! daml-parser: a **lossless** lexer, layout resolver, and parser for the Daml
2//! smart-contract language.
3//!
4//! This is the shared foundation under both `daml-lint` and `daml-fmt`. The
5//! pipeline is `lexer` → `layout` → `parse` over the [`ast`] types. The tree is
6//! lossless: the lexer records every comment and whitespace run as *trivia*
7//! (see [`lexer::lex_with_trivia`]), so a consumer can reconstruct the original
8//! bytes exactly. The linter ignores trivia and reads meaning; the formatter
9//! keeps trivia and re-prints layout. One tree, two readers.
10//!
11//! Start at [`parse::parse_module`]. For byte-faithful reconstruction from the
12//! parse tree, see [`ast_span::render_from_ast`] and [`lexer::render_lossless`].
13//! The AST modules are public for inspection by tools; parser-created trees are
14//! the supported construction path. This crate is pre-1.0, so breaking public
15//! API changes use 0.x minor bumps and patch releases should stay compatible.
16//!
17//! # Example
18//!
19//! ```
20//! let (module, diagnostics) =
21//! daml_parser::parse::parse_module("module M where\nfoo : Int\nfoo = 1\n");
22//!
23//! assert!(diagnostics.is_empty());
24//! assert_eq!(module.name, "M");
25//! ```
26
27pub mod ast;
28/// AST byte-span losslessness oracle (`render_from_ast`): reconstruct source
29/// from the parse tree to prove the tree lost nothing.
30pub mod ast_span;
31pub mod layout;
32pub mod lexer;
33pub mod parse;
34
35#[cfg(test)]
36mod diag_tests;
37#[cfg(test)]
38mod projection_tests;
39#[cfg(test)]
40mod span_tests;