Skip to main content

archidoc_engine/
ir.rs

1use archidoc_types::ModuleDoc;
2
3/// Serialize a slice of ModuleDocs to JSON IR.
4///
5/// This produces the portable intermediate representation that bridges
6/// language adapters and the core generator.
7pub fn serialize(docs: &[ModuleDoc]) -> String {
8    serde_json::to_string_pretty(docs).expect("failed to serialize ModuleDoc to JSON")
9}
10
11/// Deserialize JSON IR into ModuleDocs.
12///
13/// Returns an error message if the JSON is malformed or does not
14/// conform to the ModuleDoc[] schema.
15pub fn deserialize(json: &str) -> Result<Vec<ModuleDoc>, String> {
16    serde_json::from_str(json).map_err(|e| format!("invalid IR: {}", e))
17}
18
19/// Validate JSON IR without deserializing into a full result.
20///
21/// Returns Ok(()) if the JSON conforms to the ModuleDoc[] schema,
22/// or Err with a description of what's wrong.
23pub fn validate(json: &str) -> Result<(), String> {
24    let _: Vec<ModuleDoc> = serde_json::from_str(json)
25        .map_err(|e| format!("IR validation failed: {}", e))?;
26    Ok(())
27}