From eef2944307497ce464a901a4247b81f779c36fdc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 21 Jul 2023 19:53:02 -0400 Subject: [PATCH] Create structure for inline babel calls. --- src/compare/diff.rs | 25 +++++++++++++++++++++++++ src/parser/inline_babel_call.rs | 13 +++++++++++++ src/parser/mod.rs | 2 ++ src/parser/object.rs | 13 +++++++++++++ src/parser/token.rs | 1 + 5 files changed, 54 insertions(+) create mode 100644 src/parser/inline_babel_call.rs diff --git a/src/compare/diff.rs b/src/compare/diff.rs index fd91cee..3502130 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -25,6 +25,7 @@ use crate::parser::FootnoteReference; use crate::parser::GreaterBlock; use crate::parser::Heading; use crate::parser::HorizontalRule; +use crate::parser::InlineBabelCall; use crate::parser::Italic; use crate::parser::Keyword; use crate::parser::LatexEnvironment; @@ -166,6 +167,7 @@ fn compare_object<'s>( Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj), Object::Citation(obj) => compare_citation(source, emacs, obj), Object::CitationReference(obj) => compare_citation_reference(source, emacs, obj), + Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj), } } @@ -1388,3 +1390,26 @@ fn compare_citation_reference<'s>( children: Vec::new(), }) } + +fn compare_inline_babel_call<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s InlineBabelCall<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "inline-babel-call"; + 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(), + }) +} diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs new file mode 100644 index 0000000..1207851 --- /dev/null +++ b/src/parser/inline_babel_call.rs @@ -0,0 +1,13 @@ +use super::Context; +use crate::error::Res; +use crate::parser::util::not_yet_implemented; +use crate::parser::InlineBabelCall; + +#[tracing::instrument(ret, level = "debug")] +pub fn inline_babel_call<'r, 's>( + context: Context<'r, 's>, + input: &'s str, +) -> Res<&'s str, InlineBabelCall<'s>> { + not_yet_implemented()?; + todo!() +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d80dcea..ef727c3 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -18,6 +18,7 @@ mod footnote_reference; mod greater_block; mod greater_element; mod horizontal_rule; +mod inline_babel_call; mod keyword; mod latex_environment; mod latex_fragment; @@ -81,6 +82,7 @@ pub use object::Code; pub use object::Entity; pub use object::ExportSnippet; pub use object::FootnoteReference; +pub use object::InlineBabelCall; pub use object::Italic; pub use object::LatexFragment; pub use object::Object; diff --git a/src/parser/object.rs b/src/parser/object.rs index ffa9bf6..2deb233 100644 --- a/src/parser/object.rs +++ b/src/parser/object.rs @@ -21,6 +21,7 @@ pub enum Object<'s> { FootnoteReference(FootnoteReference<'s>), Citation(Citation<'s>), CitationReference(CitationReference<'s>), + InlineBabelCall(InlineBabelCall<'s>), } #[derive(Debug, PartialEq)] @@ -137,6 +138,11 @@ pub struct CitationReference<'s> { pub source: &'s str, } +#[derive(Debug, PartialEq)] +pub struct InlineBabelCall<'s> { + pub source: &'s str, +} + impl<'s> Source<'s> for Object<'s> { fn get_source(&'s self) -> &'s str { match self { @@ -159,6 +165,7 @@ impl<'s> Source<'s> for Object<'s> { Object::FootnoteReference(obj) => obj.source, Object::Citation(obj) => obj.source, Object::CitationReference(obj) => obj.source, + Object::InlineBabelCall(obj) => obj.source, } } } @@ -270,3 +277,9 @@ impl<'s> Source<'s> for CitationReference<'s> { self.source } } + +impl<'s> Source<'s> for InlineBabelCall<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/parser/token.rs b/src/parser/token.rs index 731147d..2ae3039 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -60,6 +60,7 @@ impl<'r, 's> Token<'r, 's> { } Object::Citation(_) => Box::new(std::iter::empty()), // TODO: Iterate over children Object::CitationReference(_) => Box::new(std::iter::empty()), // TODO: Iterate over children + Object::InlineBabelCall(_) => Box::new(std::iter::empty()), // TODO: Iterate over children }, Token::Element(elem) => match elem { Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),