diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 61f0479..9a04cec 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -19,6 +19,7 @@ use crate::parser::ExportBlock; use crate::parser::ExportSnippet; use crate::parser::FixedWidthArea; use crate::parser::FootnoteDefinition; +use crate::parser::FootnoteReference; use crate::parser::GreaterBlock; use crate::parser::Heading; use crate::parser::HorizontalRule; @@ -160,6 +161,7 @@ fn compare_object<'s>( 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), + Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj), } } @@ -1313,3 +1315,26 @@ fn compare_export_snippet<'s>( children: Vec::new(), }) } + +fn compare_footnote_reference<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s FootnoteReference<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "footnote-reference"; + 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/footnote_reference.rs b/src/parser/footnote_reference.rs new file mode 100644 index 0000000..c43253b --- /dev/null +++ b/src/parser/footnote_reference.rs @@ -0,0 +1,13 @@ +use super::Context; +use crate::error::Res; +use crate::parser::FootnoteReference; +use crate::parser::util::not_yet_implemented; + +#[tracing::instrument(ret, level = "debug")] +pub fn footnote_reference<'r, 's>( + context: Context<'r, 's>, + input: &'s str, +) -> Res<&'s str, FootnoteReference<'s>> { + not_yet_implemented()?; + todo!() +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 45d687b..6cf9bbc 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -12,6 +12,7 @@ mod exiting; mod export_snippet; mod fixed_width_area; mod footnote_definition; +mod footnote_reference; mod greater_block; mod greater_element; mod horizontal_rule; @@ -75,6 +76,7 @@ pub use object::Bold; pub use object::Code; pub use object::Entity; pub use object::ExportSnippet; +pub use object::FootnoteReference; 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 9bd56ef..481408f 100644 --- a/src/parser/object.rs +++ b/src/parser/object.rs @@ -18,6 +18,7 @@ pub enum Object<'s> { Entity(Entity<'s>), LatexFragment(LatexFragment<'s>), ExportSnippet(ExportSnippet<'s>), + FootnoteReference(FootnoteReference<'s>), } #[derive(Debug, PartialEq)] @@ -117,6 +118,13 @@ pub struct ExportSnippet<'s> { pub contents: Option<&'s str>, } +#[derive(Debug, PartialEq)] +pub struct FootnoteReference<'s> { + pub source: &'s str, + pub label: &'s str, + pub definition: Vec>, +} + impl<'s> Source<'s> for Object<'s> { fn get_source(&'s self) -> &'s str { match self { @@ -136,6 +144,7 @@ impl<'s> Source<'s> for Object<'s> { Object::Entity(obj) => obj.source, Object::LatexFragment(obj) => obj.source, Object::ExportSnippet(obj) => obj.source, + Object::FootnoteReference(obj) => obj.source, } } } @@ -229,3 +238,9 @@ impl<'s> Source<'s> for ExportSnippet<'s> { self.source } } + +impl<'s> Source<'s> for FootnoteReference<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index e84992b..8ee65d3 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -10,6 +10,7 @@ use crate::error::Res; use crate::parser::angle_link::angle_link; use crate::parser::entity::entity; use crate::parser::export_snippet::export_snippet; +use crate::parser::footnote_reference::footnote_reference; use crate::parser::latex_fragment::latex_fragment; use crate::parser::object::Object; use crate::parser::org_macro::org_macro; @@ -23,10 +24,14 @@ pub fn standard_set_object<'r, 's>( context: Context<'r, 's>, input: &'s str, ) -> Res<&'s str, Object<'s>> { - // TODO: footnote references, citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup. + // TODO: citations (NOT citation references), inline babel calls, inline source blocks, line breaks, links, macros, targets and radio targets, statistics cookies, subscript and superscript, timestamps, and text markup. not(|i| context.check_exit_matcher(i))(input)?; alt(( + map( + parser_with_context!(footnote_reference)(context), + Object::FootnoteReference, + ), map( parser_with_context!(export_snippet)(context), Object::ExportSnippet, @@ -79,6 +84,10 @@ pub fn any_object_except_plain_text<'r, 's>( ) -> Res<&'s str, Object<'s>> { // Used for exit matchers so this does not check exit matcher condition. alt(( + map( + parser_with_context!(footnote_reference)(context), + Object::FootnoteReference, + ), map( parser_with_context!(export_snippet)(context), Object::ExportSnippet, diff --git a/src/parser/token.rs b/src/parser/token.rs index c97cbe1..5bbf740 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -55,6 +55,9 @@ impl<'r, 's> Token<'r, 's> { Object::Entity(_) => Box::new(std::iter::empty()), Object::LatexFragment(_) => Box::new(std::iter::empty()), Object::ExportSnippet(_) => Box::new(std::iter::empty()), + Object::FootnoteReference(inner) => { + Box::new(inner.definition.iter().map(Token::Object)) + } }, Token::Element(elem) => match elem { Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),