Create structure for subscript and superscript.
This commit is contained in:
parent
7d73ac4bf6
commit
993c73dc9f
@ -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<DiffResult, Box<dyn std::error::Error>> {
|
||||
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<DiffResult, Box<dyn std::error::Error>> {
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
20
src/parser/subscript_and_superscript.rs
Normal file
20
src/parser/subscript_and_superscript.rs
Normal file
@ -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!()
|
||||
}
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user