Compare properties of subscript and superscript.

This commit is contained in:
Tom Alexander
2023-10-09 19:51:31 -04:00
parent 86dd526dde
commit d1ef83afca
3 changed files with 89 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ use crate::error::MyError;
use crate::error::Res;
use crate::parser::util::get_consumed;
use crate::types::Object;
use crate::types::PlainText;
use crate::types::Subscript;
use crate::types::Superscript;
@@ -57,14 +58,22 @@ pub(crate) fn subscript<'b, 'g, 'r, 's>(
// We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
let (remaining, _) = tag("_")(input)?;
pre(input)?;
let (remaining, _body) = script_body(context, remaining)?;
let (remaining, body) = script_body(context, remaining)?;
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
let (use_brackets, body) = match body {
ScriptBody::Braceless(text) => (false, vec![Object::PlainText(PlainText { source: text })]),
ScriptBody::WithBraces(body) => (true, body),
};
Ok((
remaining,
Subscript {
source: source.into(),
use_brackets,
children: body,
},
))
}
@@ -80,14 +89,22 @@ pub(crate) fn superscript<'b, 'g, 'r, 's>(
// We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
let (remaining, _) = tag("^")(input)?;
pre(input)?;
let (remaining, _body) = script_body(context, remaining)?;
let (remaining, body) = script_body(context, remaining)?;
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
let (use_brackets, body) = match body {
ScriptBody::Braceless(text) => (false, vec![Object::PlainText(PlainText { source: text })]),
ScriptBody::WithBraces(body) => (true, body),
};
Ok((
remaining,
Superscript {
source: source.into(),
use_brackets,
children: body,
},
))
}