cml-rs 0.4.0

Content Markup Language (CML) v0.2 parser, generator, validator, and embedding store for structured documents
Documentation
//! # CML (Content Markup Language)
//!
//! CML is a semantic markup language designed for long-term interpretable content storage.
//! It separates content from presentation and enables efficient vector-based semantic search.
//!
//! ## CML Structure
//!
//! ```xml
//! <cml profile="core" version="0.2" encoding="utf-8">
//!   <header>
//!     <title>Document Title</title>
//!     <author role="author">Author Name</author>
//!     <date type="created" when="2025-12-22"/>
//!   </header>
//!   <body>
//!     <section id="intro">
//!       <heading size="1">Introduction</heading>
//!       <paragraph>Content here with <em>inline elements</em>.</paragraph>
//!     </section>
//!   </body>
//!   <footer>
//!   </footer>
//! </cml>
//! ```
//!
//! ## Features
//!
//! - **Profile-based schemas**: Domain-specific document structures (law, code, edu)
//! - **Pathless references**: `namespace:identifier` format (e.g., `president:47`)
//! - **Active documents**: Currency conversion, date localization (future)
//! - **Validation**: ID uniqueness, reference integrity, structural correctness
//!
//! ## Usage
//!
//! ```rust
//! use cml_rs::{CmlParser, CmlGenerator, CmlValidator};
//!
//! // Parse CML
//! let xml = r#"<cml profile="core" version="0.2" encoding="utf-8">
//!   <header><title>Test</title></header>
//!   <body><paragraph>Hello!</paragraph></body>
//!   <footer></footer>
//! </cml>"#;
//!
//! let doc = CmlParser::parse_str(xml)?;
//!
//! // Validate
//! CmlValidator::validate(&doc)?;
//!
//! // Generate
//! let xml = CmlGenerator::generate(&doc)?;
//! # Ok::<(), cml_rs::CmlError>(())
//! ```

// Core CML modules
pub mod generator;
pub mod parser;
pub mod profile;
pub mod types;
pub mod validator;

// Utilities
// TODO: Revisit chunker and embedding_store after the semantic compiler move.
pub mod chunker;
pub mod embedding_store;
pub mod id_generator;

// Re-export primary types and functions
pub use generator::CmlGenerator;
pub use parser::CmlParser;
pub use profile::{Profile, ProfileRegistry, ResolvedProfile};
pub use types::*;
pub use validator::CmlValidator;

// Re-export utilities
// TODO: Revisit chunker and embedding_store after the semantic compiler move.
pub use chunker::{Chunk, CmlChunker, CHUNK_OVERLAP_TOKENS, MAX_CHUNK_TOKENS};
pub use embedding_store::{ChunkMatch, EmbeddingStore, MatchType, EMBEDDING_DIM};
pub use id_generator::{BookstackIdGenerator, CodeIdGenerator, ElementId, LegalIdGenerator};

/// Result type for CML operations
pub type Result<T> = std::result::Result<T, CmlError>;

/// Errors that can occur during CML processing
#[derive(Debug, thiserror::Error)]
pub enum CmlError {
    #[error("XML parsing error: {0}")]
    XmlError(#[from] quick_xml::Error),

    #[error("XML attribute error: {0}")]
    AttrError(#[from] quick_xml::events::attributes::AttrError),

    #[error("Invalid document structure: {0}")]
    InvalidStructure(String),

    #[error("Missing required attribute: {0}")]
    MissingAttribute(String),

    #[error("Invalid attribute value: {0}")]
    InvalidAttribute(String),

    #[error("Schema validation failed: {0}")]
    ValidationError(String),

    #[error("Duplicate ID: {0}")]
    DuplicateId(String),

    #[error("Reference not found: {0}")]
    ReferenceNotFound(String),

    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("UTF-8 error: {0}")]
    Utf8Error(#[from] std::string::FromUtf8Error),
}