Expand description
Code emission: IR TypeGraph → Rust source string.
The main entry point is emit, which takes a fully-lowered TypeGraph
and returns a formatted Rust source file as a String.
§Pipeline
- Each
TypeDefvariant is dispatched to the appropriate submodule. - Each submodule returns a
proc_macro2::TokenStream. - All token streams are collected and formatted with
prettyplease.
§Example
use mx20022_codegen::{xsd, ir, emit};
let schema = xsd::parse_str(r#"<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:example">
<xs:element name="Root" type="RootType"/>
<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="Id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>"#).unwrap();
let graph = ir::lower(&schema).unwrap();
let code = emit::emit(&graph);
assert!(code.contains("pub struct RootType"));