zenith_core/parse/mod.rs
1//! Parse layer re-exports and the `KdlSource` trait.
2
3pub mod kdl_adapter;
4pub mod policy;
5pub mod transform;
6
7pub use kdl_adapter::KdlAdapter;
8pub use policy::{parse_brand_contract, parse_diagnostic_policy};
9
10use crate::ast::Document;
11use crate::error::{FormatError, ParseError};
12
13/// Contract for a type that can parse and format `.zen` source bytes.
14pub trait KdlSource {
15 /// Parse raw `.zen` bytes into a `Document` AST.
16 ///
17 /// # Errors
18 ///
19 /// Returns a `ParseError` if the bytes are not valid UTF-8, not valid KDL,
20 /// or do not conform to the minimal Zenith schema.
21 fn parse(&self, source: &[u8]) -> Result<Document, ParseError>;
22
23 /// Serialize a `Document` AST back to canonical `.zen` bytes.
24 ///
25 /// The output is idempotent: `format(format(doc)) == format(doc)` for all
26 /// valid documents. Returns `Err` only for genuinely un-serializable states
27 /// (unreachable for valid v0 input).
28 fn format(&self, doc: &Document) -> Result<Vec<u8>, FormatError>;
29}