Skip to main content

lex_babel/formats/rfc_xml/
mod.rs

1use crate::error::FormatError;
2use crate::format::{Format, SerializedDocument};
3use lex_core::lex::ast::Document;
4use std::collections::HashMap;
5
6mod parser;
7
8pub struct RfcXmlFormat;
9
10impl Format for RfcXmlFormat {
11    fn name(&self) -> &str {
12        "rfc_xml"
13    }
14
15    fn description(&self) -> &str {
16        "IETF RFC XML Format (v3)"
17    }
18
19    fn file_extensions(&self) -> &[&str] {
20        &["rfcxml"]
21    }
22
23    fn supports_parsing(&self) -> bool {
24        true
25    }
26
27    fn supports_serialization(&self) -> bool {
28        false
29    }
30
31    fn parse(&self, source: &str) -> Result<Document, FormatError> {
32        // Parse XML to IR
33        let ir_doc = parser::parse_to_ir(source)?;
34
35        // Convert IR to Lex AST using the common converter
36        Ok(crate::from_ir(&ir_doc))
37    }
38
39    fn serialize(&self, _doc: &Document) -> Result<String, FormatError> {
40        Err(FormatError::NotSupported(
41            "RFC XML serialization not implemented".to_string(),
42        ))
43    }
44
45    fn serialize_with_options(
46        &self,
47        _doc: &Document,
48        _options: &HashMap<String, String>,
49    ) -> Result<SerializedDocument, FormatError> {
50        Err(FormatError::NotSupported(
51            "RFC XML serialization not implemented".to_string(),
52        ))
53    }
54}