Skip to main content

lex_babel/formats/rfc_xml/
mod.rs

1//! IETF RFC XML (v3) format implementation
2//!
3//! # Status: Experimental
4//!
5//! This is a parse-only proof-of-concept import for IETF RFC XML (v3)
6//! documents. It is kept in-tree because it's a useful demo of
7//! Lex-as-target, not because it is a release-quality format. The
8//! project invests **no bespoke time** here — only improvements that
9//! fall out of IR-symmetry work for free.
10//!
11//! Do not invest engineering effort in this format unless the v1
12//! interop bar (Markdown round-trip, HTML/PDF export) is already
13//! solid. See the full tiering at `comms/docs/interop-scope.lex`
14//! in-repo, or
15//! <https://github.com/lex-fmt/comms/blob/main/docs/interop-scope.lex>
16//! on the web.
17
18use crate::error::FormatError;
19use crate::format::{Format, SerializedDocument};
20use lex_core::lex::ast::Document;
21use std::collections::HashMap;
22
23mod parser;
24
25pub struct RfcXmlFormat;
26
27impl Format for RfcXmlFormat {
28    fn name(&self) -> &str {
29        "rfc_xml"
30    }
31
32    fn description(&self) -> &str {
33        "IETF RFC XML Format (v3)"
34    }
35
36    fn file_extensions(&self) -> &[&str] {
37        &["rfcxml"]
38    }
39
40    fn supports_parsing(&self) -> bool {
41        true
42    }
43
44    fn supports_serialization(&self) -> bool {
45        false
46    }
47
48    fn parse(&self, source: &str) -> Result<Document, FormatError> {
49        // Parse XML to IR
50        let ir_doc = parser::parse_to_ir(source)?;
51
52        // Convert IR to Lex AST using the common converter
53        Ok(crate::from_ir(&ir_doc))
54    }
55
56    fn serialize(&self, _doc: &Document) -> Result<String, FormatError> {
57        Err(FormatError::NotSupported(
58            "RFC XML serialization not implemented".to_string(),
59        ))
60    }
61
62    fn serialize_with_options(
63        &self,
64        _doc: &Document,
65        _options: &HashMap<String, String>,
66    ) -> Result<SerializedDocument, FormatError> {
67        Err(FormatError::NotSupported(
68            "RFC XML serialization not implemented".to_string(),
69        ))
70    }
71}