Create structure for export snippets.

This commit is contained in:
Tom Alexander 2023-07-19 00:09:16 -04:00
parent eb03342506
commit 1fb8ce9af6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 56 additions and 0 deletions

View File

@ -16,6 +16,7 @@ use crate::parser::Element;
use crate::parser::Entity;
use crate::parser::ExampleBlock;
use crate::parser::ExportBlock;
use crate::parser::ExportSnippet;
use crate::parser::FixedWidthArea;
use crate::parser::FootnoteDefinition;
use crate::parser::GreaterBlock;
@ -158,6 +159,7 @@ fn compare_object<'s>(
Object::OrgMacro(obj) => compare_org_macro(source, emacs, obj),
Object::Entity(obj) => compare_entity(source, emacs, obj),
Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj),
Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj),
}
}
@ -1288,3 +1290,26 @@ fn compare_latex_fragment<'s>(
children: Vec::new(),
})
}
fn compare_export_snippet<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s ExportSnippet<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "export-snippet";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: Vec::new(),
})
}

View File

@ -0,0 +1,13 @@
use super::Context;
use crate::error::Res;
use crate::parser::util::not_yet_implemented;
use crate::parser::ExportSnippet;
#[tracing::instrument(ret, level = "debug")]
pub fn export_snippet<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, ExportSnippet<'s>> {
not_yet_implemented()?;
todo!()
}

View File

@ -9,6 +9,7 @@ mod element;
mod element_parser;
mod entity;
mod exiting;
mod export_snippet;
mod fixed_width_area;
mod footnote_definition;
mod greater_block;
@ -73,6 +74,7 @@ pub use object::AngleLink;
pub use object::Bold;
pub use object::Code;
pub use object::Entity;
pub use object::ExportSnippet;
pub use object::Italic;
pub use object::LatexFragment;
pub use object::Object;

View File

@ -17,6 +17,7 @@ pub enum Object<'s> {
OrgMacro(OrgMacro<'s>),
Entity(Entity<'s>),
LatexFragment(LatexFragment<'s>),
ExportSnippet(ExportSnippet<'s>),
}
#[derive(Debug, PartialEq)]
@ -109,6 +110,13 @@ pub struct LatexFragment<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct ExportSnippet<'s> {
pub source: &'s str,
pub backend: &'s str,
pub contents: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@ -127,6 +135,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::OrgMacro(obj) => obj.source,
Object::Entity(obj) => obj.source,
Object::LatexFragment(obj) => obj.source,
Object::ExportSnippet(obj) => obj.source,
}
}
}
@ -214,3 +223,9 @@ impl<'s> Source<'s> for LatexFragment<'s> {
self.source
}
}
impl<'s> Source<'s> for ExportSnippet<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@ -54,6 +54,7 @@ impl<'r, 's> Token<'r, 's> {
Object::OrgMacro(_) => Box::new(std::iter::empty()),
Object::Entity(_) => Box::new(std::iter::empty()),
Object::LatexFragment(_) => Box::new(std::iter::empty()),
Object::ExportSnippet(_) => Box::new(std::iter::empty()),
},
Token::Element(elem) => match elem {
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),