Create structure for inline babel calls.

This commit is contained in:
Tom Alexander 2023-07-21 19:53:02 -04:00
parent 1e2ea17a9c
commit eef2944307
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 54 additions and 0 deletions

View File

@ -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<DiffResult, Box<dyn std::error::Error>> {
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(),
})
}

View File

@ -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!()
}

View File

@ -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;

View File

@ -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
}
}

View File

@ -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)),