Skip to main content

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//! ```rust
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
27/// Lossless AST node types produced by the parser.
28pub mod ast;
29/// AST byte-span losslessness oracle (`render_from_ast`): reconstruct source
30/// from the parse tree to prove the tree lost nothing.
31pub mod ast_span;
32/// Indentation-sensitive layout resolver.
33///
34/// Inserts virtual braces and semicolons for the parser.
35pub mod layout;
36/// Lexer and token/trivia types for Daml source text.
37pub mod lexer;
38/// Recursive-descent parser entry points and diagnostics.
39pub mod parse;
40
41#[cfg(test)]
42mod diag_tests;
43#[cfg(test)]
44mod projection_tests;
45#[cfg(test)]
46mod span_tests;