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 tolerant parsing, or
12//! [`parse::parse_module_strict`] when any diagnostic should fail the caller.
13//! For byte-faithful reconstruction from the parse tree, see
14//! [`ast_span::render_from_ast`] and [`lexer::render_lossless`].
15//!
16//! ## API posture
17//!
18//! This crate is pre-1.0. Its public AST/IR-like types are intentionally direct
19//! data shapes that tools consume directly; additions or shape changes are
20//! SemVer-relevant and should be treated as breaking contract changes.
21//! Prefer adding helpers only when they can be used without changing these
22//! shapes, and use `#[non_exhaustive]` enums/variants for forward-safe
23//! extension when future variants are expected.
24//!
25//! Parser-created trees are the supported construction path.
26//!
27//! # Example
28//!
29//! ```rust
30//! let result =
31//!     daml_parser::parse::parse_module("module M where\nfoo : Int\nfoo = 1\n");
32//!
33//! assert!(result.diagnostics.is_empty());
34//! assert_eq!(result.module.name, "M");
35//! ```
36
37/// Lossless AST node types produced by the parser.
38pub mod ast;
39/// AST byte-span losslessness oracle (`render_from_ast`): reconstruct source
40/// from the parse tree to prove the tree lost nothing.
41pub mod ast_span;
42/// Indentation-sensitive layout resolver.
43///
44/// Inserts virtual braces and semicolons for the parser.
45pub mod layout;
46/// Lexer and token/trivia types for Daml source text.
47pub mod lexer;
48/// Recursive-descent parser entry points and diagnostics.
49pub mod parse;