Implement example block and export block.

main
Tom Alexander 5 months ago
parent 60a4835590
commit 3131f8ac64
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -3,16 +3,35 @@ use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::src_block::WasmNumberLines;
use super::src_block::WasmNumberLinesWrapper;
use super::src_block::WasmRetainLabels;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::CharOffsetInLine;
use crate::types::ExampleBlock;
use crate::types::GetAffiliatedKeywords;
use crate::types::RetainLabels;
use crate::types::SwitchNumberLines;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmExampleBlock {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
pub(crate) value: String,
pub(crate) switches: Option<String>,
#[serde(rename = "number-lines")]
pub(crate) number_lines: Option<WasmNumberLinesWrapper>,
#[serde(rename = "preserve-indent")]
pub(crate) preserve_indent: Option<CharOffsetInLine>,
#[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<String>,
}
to_wasm!(
@ -21,12 +40,35 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::ExampleBlock(original) },
{ "TODO".into() },
{ "example-block".into() },
{
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
Ok((
Vec::new(),
WasmExampleBlock {
additional_properties: AdditionalProperties::default(),
additional_properties,
value: original.get_value().into_owned(),
switches: original.switches.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()),
},
))
}

@ -7,12 +7,16 @@ use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::ExportBlock;
use crate::types::GetAffiliatedKeywords;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmExportBlock {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
#[serde(rename = "type")]
pub(crate) export_type: Option<String>,
pub(crate) value: String,
}
to_wasm!(
@ -21,12 +25,18 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::ExportBlock(original) },
{ "TODO".into() },
{ "export-block".into() },
{
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
Ok((
Vec::new(),
WasmExportBlock {
additional_properties: AdditionalProperties::default(),
additional_properties,
export_type: original.get_export_type(),
value: original.get_value().into_owned(),
},
))
}

@ -36,13 +36,13 @@ pub struct WasmSrcBlock {
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
enum WasmRetainLabels {
pub(crate) enum WasmRetainLabels {
YesNo(bool),
Keep(CharOffsetInLine),
}
#[derive(Debug, Serialize, Deserialize)]
enum WasmNumberLines {
pub(crate) enum WasmNumberLines {
#[serde(rename = "new")]
New(LineNumber),
#[serde(rename = "continued")]
@ -52,9 +52,9 @@ enum WasmNumberLines {
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename = "number-lines")]
#[serde(tag = "number-lines")]
struct WasmNumberLinesWrapper {
pub(crate) struct WasmNumberLinesWrapper {
#[serde(flatten)]
inner: WasmNumberLines,
pub(crate) inner: WasmNumberLines,
}
to_wasm!(

Loading…
Cancel
Save