diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 1268fb3..127b15c 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -24,6 +24,7 @@ use crate::parser::Italic; use crate::parser::Keyword; use crate::parser::LatexEnvironment; use crate::parser::Object; +use crate::parser::OrgMacro; use crate::parser::Paragraph; use crate::parser::PlainLink; use crate::parser::PlainList; @@ -152,6 +153,7 @@ fn compare_object<'s>( Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj), Object::PlainLink(obj) => compare_plain_link(source, emacs, obj), Object::AngleLink(obj) => compare_angle_link(source, emacs, obj), + Object::OrgMacro(obj) => compare_org_macro(source, emacs, obj), } } @@ -1213,3 +1215,26 @@ fn compare_angle_link<'s>( children: Vec::new(), }) } + +fn compare_org_macro<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s OrgMacro<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "macro"; + 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/mod.rs b/src/parser/mod.rs index acb620e..df09653 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -20,6 +20,7 @@ mod lesser_element; mod list; mod object; mod object_parser; +mod org_macro; mod paragraph; mod parser_context; mod parser_with_context; @@ -70,6 +71,7 @@ pub use object::Bold; pub use object::Code; pub use object::Italic; pub use object::Object; +pub use object::OrgMacro; pub use object::PlainLink; pub use object::PlainText; pub use object::RadioLink; diff --git a/src/parser/object.rs b/src/parser/object.rs index bf4b85e..f7ca528 100644 --- a/src/parser/object.rs +++ b/src/parser/object.rs @@ -2,11 +2,6 @@ use super::source::Source; #[derive(Debug, PartialEq)] pub enum Object<'s> { - RegularLink(RegularLink<'s>), - RadioLink(RadioLink<'s>), - RadioTarget(RadioTarget<'s>), - PlainLink(PlainLink<'s>), - AngleLink(AngleLink<'s>), Bold(Bold<'s>), Italic(Italic<'s>), Underline(Underline<'s>), @@ -14,6 +9,12 @@ pub enum Object<'s> { Code(Code<'s>), Verbatim(Verbatim<'s>), PlainText(PlainText<'s>), + RegularLink(RegularLink<'s>), + RadioLink(RadioLink<'s>), + RadioTarget(RadioTarget<'s>), + PlainLink(PlainLink<'s>), + AngleLink(AngleLink<'s>), + OrgMacro(OrgMacro<'s>), } #[derive(Debug, PartialEq)] @@ -88,6 +89,13 @@ pub struct AngleLink<'s> { pub path: &'s str, } +#[derive(Debug, PartialEq)] +pub struct OrgMacro<'s> { + pub source: &'s str, + pub macro_name: &'s str, + pub macro_args: Vec<&'s str>, +} + impl<'s> Source<'s> for Object<'s> { fn get_source(&'s self) -> &'s str { match self { @@ -103,6 +111,7 @@ impl<'s> Source<'s> for Object<'s> { Object::RadioTarget(obj) => obj.source, Object::PlainLink(obj) => obj.source, Object::AngleLink(obj) => obj.source, + Object::OrgMacro(obj) => obj.source, } } } @@ -172,3 +181,9 @@ impl<'s> Source<'s> for AngleLink<'s> { self.source } } + +impl<'s> Source<'s> for OrgMacro<'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 e21231f..5d380c8 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -8,6 +8,7 @@ use super::regular_link::regular_link; use super::Context; use crate::error::Res; use crate::parser::angle_link::angle_link; +use crate::parser::org_macro::org_macro; use crate::parser::object::Object; use crate::parser::plain_link::plain_link; use crate::parser::radio_link::radio_link; @@ -35,6 +36,7 @@ pub fn standard_set_object<'r, 's>( ), map(parser_with_context!(plain_link)(context), Object::PlainLink), map(parser_with_context!(angle_link)(context), Object::AngleLink), + map(parser_with_context!(org_macro)(context), Object::OrgMacro), map(parser_with_context!(plain_text)(context), Object::PlainText), ))(input) } @@ -72,6 +74,7 @@ pub fn any_object_except_plain_text<'r, 's>( ), map(parser_with_context!(plain_link)(context), Object::PlainLink), map(parser_with_context!(angle_link)(context), Object::AngleLink), + map(parser_with_context!(org_macro)(context), Object::OrgMacro), ))(input) } diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs new file mode 100644 index 0000000..05d43a8 --- /dev/null +++ b/src/parser/org_macro.rs @@ -0,0 +1,10 @@ +use super::Context; +use crate::error::Res; +use crate::parser::object::OrgMacro; +use crate::parser::util::not_yet_implemented; + +#[tracing::instrument(ret, level = "debug")] +pub fn org_macro<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, OrgMacro<'s>> { + not_yet_implemented()?; + todo!(); +}