diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 74cde67..79741bd 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1,5 +1,7 @@ use super::util::assert_bounds; use super::util::assert_name; +use crate::parser::Subscript; +use crate::parser::Superscript; use crate::parser::sexp::Token; use crate::parser::AngleLink; use crate::parser::Bold; @@ -176,6 +178,8 @@ fn compare_object<'s>( Object::LineBreak(obj) => compare_line_break(source, emacs, obj), Object::Target(obj) => compare_target(source, emacs, obj), Object::StatisticsCookie(obj) => compare_statistics_cookie(source, emacs, obj), + Object::Subscript(obj) => compare_subscript(source, emacs, obj), + Object::Superscript(obj) => compare_superscript(source, emacs, obj), } } @@ -1513,3 +1517,49 @@ fn compare_statistics_cookie<'s>( children: Vec::new(), }) } + +fn compare_subscript<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s Subscript<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "subscript"; + 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(), + }) +} + +fn compare_superscript<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s Superscript<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "superscript"; + 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 3f0f284..a37107c 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -43,6 +43,7 @@ mod regular_link; pub mod sexp; mod source; mod statistics_cookie; +mod subscript_and_superscript; mod table; mod target; mod text_markup; @@ -100,6 +101,8 @@ pub use object::RadioTarget; pub use object::RegularLink; pub use object::StatisticsCookie; pub use object::StrikeThrough; +pub use object::Subscript; +pub use object::Superscript; pub use object::Target; pub use object::Underline; pub use object::Verbatim; diff --git a/src/parser/object.rs b/src/parser/object.rs index 300e038..d9acdd3 100644 --- a/src/parser/object.rs +++ b/src/parser/object.rs @@ -26,6 +26,8 @@ pub enum Object<'s> { LineBreak(LineBreak<'s>), Target(Target<'s>), StatisticsCookie(StatisticsCookie<'s>), + Subscript(Subscript<'s>), + Superscript(Superscript<'s>), } #[derive(Debug, PartialEq)] @@ -167,6 +169,16 @@ pub struct StatisticsCookie<'s> { pub source: &'s str, } +#[derive(Debug, PartialEq)] +pub struct Subscript<'s> { + pub source: &'s str, +} + +#[derive(Debug, PartialEq)] +pub struct Superscript<'s> { + pub source: &'s str, +} + impl<'s> Source<'s> for Object<'s> { fn get_source(&'s self) -> &'s str { match self { @@ -194,6 +206,8 @@ impl<'s> Source<'s> for Object<'s> { Object::LineBreak(obj) => obj.source, Object::Target(obj) => obj.source, Object::StatisticsCookie(obj) => obj.source, + Object::Subscript(obj) => obj.source, + Object::Superscript(obj) => obj.source, } } } @@ -335,3 +349,15 @@ impl<'s> Source<'s> for StatisticsCookie<'s> { self.source } } + +impl<'s> Source<'s> for Subscript<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> Source<'s> for Superscript<'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 549aea8..b15819e 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -22,6 +22,8 @@ use crate::parser::plain_link::plain_link; use crate::parser::radio_link::radio_link; use crate::parser::radio_link::radio_target; use crate::parser::statistics_cookie::statistics_cookie; +use crate::parser::subscript_and_superscript::subscript; +use crate::parser::subscript_and_superscript::superscript; use crate::parser::target::target; use crate::parser::text_markup::text_markup; @@ -34,6 +36,11 @@ pub fn standard_set_object<'r, 's>( not(|i| context.check_exit_matcher(i))(input)?; alt(( + map(parser_with_context!(subscript)(context), Object::Subscript), + map( + parser_with_context!(superscript)(context), + Object::Superscript, + ), map( parser_with_context!(statistics_cookie)(context), Object::StatisticsCookie, @@ -84,10 +91,14 @@ pub fn minimal_set_object<'r, 's>( context: Context<'r, 's>, input: &'s str, ) -> Res<&'s str, Object<'s>> { - // TODO: superscripts and subscripts not(|i| context.check_exit_matcher(i))(input)?; alt(( + map(parser_with_context!(subscript)(context), Object::Subscript), + map( + parser_with_context!(superscript)(context), + Object::Superscript, + ), map(parser_with_context!(entity)(context), Object::Entity), map( parser_with_context!(latex_fragment)(context), @@ -105,6 +116,11 @@ 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!(subscript)(context), Object::Subscript), + map( + parser_with_context!(superscript)(context), + Object::Superscript, + ), map( parser_with_context!(statistics_cookie)(context), Object::StatisticsCookie, diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs new file mode 100644 index 0000000..4cb85da --- /dev/null +++ b/src/parser/subscript_and_superscript.rs @@ -0,0 +1,20 @@ +use super::Context; +use crate::error::Res; +use crate::parser::util::not_yet_implemented; +use crate::parser::Subscript; +use crate::parser::Superscript; + +#[tracing::instrument(ret, level = "debug")] +pub fn subscript<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Subscript<'s>> { + not_yet_implemented()?; + todo!() +} + +#[tracing::instrument(ret, level = "debug")] +pub fn superscript<'r, 's>( + context: Context<'r, 's>, + input: &'s str, +) -> Res<&'s str, Superscript<'s>> { + not_yet_implemented()?; + todo!() +} diff --git a/src/parser/token.rs b/src/parser/token.rs index b9ea9dd..45f51ba 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -65,6 +65,8 @@ impl<'r, 's> Token<'r, 's> { Object::LineBreak(_) => Box::new(std::iter::empty()), Object::Target(_) => Box::new(std::iter::empty()), Object::StatisticsCookie(_) => Box::new(std::iter::empty()), + Object::Subscript(_) => Box::new(std::iter::empty()), // TODO: Iterate over children + Object::Superscript(_) => 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)),