lex_core/lex/assembling.rs
1//! Assembling module
2//!
3//! The assembling stage processes parsed AST nodes to attach metadata and perform
4//! post-parsing transformations. Unlike the parsing stage which converts tokens to AST,
5//! assembling stages operate on the AST itself.
6//!
7//! The builder returns the root session tree, so assembling first wraps it in a
8//! [`Document`](crate::lex::ast::Document). Annotations, which are metadata, are always
9//! attached to AST nodes so they can be very targeted. Only with the full document in
10//! place can we attach annotations to their correct target nodes.
11//!
12//! This is harder than it seems. Keeping Lex ethos of not enforcing structure, this needs
13//! to deal with several ambiguous cases, including some complex logic for calculating
14//! "human understanding" distance between elements.
15//!
16//! Current stages:
17//!
18//! - `attach_root`: Wraps the built session tree in a [`Document`].
19//! - `attach_annotations`: Attaches annotations from content to AST nodes as metadata.
20//! See [attach_annotations](stages::attach_annotations) for details.
21//!
22//! Note on Document Title:
23//! The document title is extracted during the AST building phase (in `AstTreeBuilder`),
24//! just before the assembling stages begin. It promotes the first paragraph (if followed
25//! by blank lines) to be the document title.
26
27pub mod stages;
28
29pub use stages::{AttachAnnotations, AttachRoot};