use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use super::AdditionalProperties; use crate::types::CharOffsetInLine; use crate::types::GetAffiliatedKeywords; use crate::types::LineNumber; use crate::types::RetainLabels; use crate::types::SrcBlock; use crate::types::SwitchNumberLines; use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] pub struct WasmSrcBlock { #[serde(flatten)] pub(crate) additional_properties: AdditionalProperties, pub(crate) language: Option, pub(crate) value: String, pub(crate) switches: Option, pub(crate) parameters: Option, #[serde(rename = "number-lines")] pub(crate) number_lines: Option, #[serde(rename = "preserve-indent")] pub(crate) preserve_indent: Option, #[serde(rename = "retain-labels")] pub(crate) retain_labels: WasmRetainLabels, #[serde(rename = "use-labels")] pub(crate) use_labels: bool, #[serde(rename = "label-fmt")] pub(crate) label_format: Option, } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub(crate) enum WasmRetainLabels { YesNo(bool), Keep(CharOffsetInLine), } #[derive(Debug, Serialize, Deserialize)] pub(crate) enum WasmNumberLines { #[serde(rename = "new")] New(LineNumber), #[serde(rename = "continued")] Continued(LineNumber), } #[derive(Debug, Serialize, Deserialize)] #[serde(rename = "number-lines")] #[serde(tag = "number-lines")] pub(crate) struct WasmNumberLinesWrapper { #[serde(flatten)] pub(crate) inner: WasmNumberLines, } to_wasm!( WasmSrcBlock, SrcBlock<'s>, original, wasm_context, { WasmAstNode::SrcBlock(original) }, { "src-block".into() }, { let additional_properties = original .get_affiliated_keywords() .to_wasm(wasm_context.clone())?; Ok(( Vec::new(), WasmSrcBlock { additional_properties, language: original.language.map(|s| s.to_owned()), value: original.get_value().into_owned(), switches: original.switches.map(|s| s.to_owned()), parameters: original.parameters.map(|s| s.to_owned()), number_lines: match original.number_lines { None => None, Some(SwitchNumberLines::New(n)) => Some(WasmNumberLinesWrapper { inner: WasmNumberLines::New(n), }), Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper { inner: WasmNumberLines::Continued(n), }), }, preserve_indent: original.preserve_indent, retain_labels: match original.retain_labels { RetainLabels::No => WasmRetainLabels::YesNo(false), RetainLabels::Yes => WasmRetainLabels::YesNo(true), RetainLabels::Keep(n) => WasmRetainLabels::Keep(n), }, use_labels: original.use_labels, label_format: original.label_format.map(|s| s.to_owned()), }, )) } );