Add a detect object function similar to the detect element function.

This commit is contained in:
Tom Alexander
2023-09-07 02:59:08 -04:00
parent ba291c6776
commit 76a81b73ac
3 changed files with 37 additions and 2 deletions

View File

@@ -30,6 +30,19 @@ use crate::types::Object;
use crate::types::Subscript;
use crate::types::Superscript;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn detect_subscript_or_superscript<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
// This does not have to detect all valid subscript/superscript but all that it detects must be valid.
let (remaining, _) = one_of("_^")(input)?;
pre(input)?;
if tag::<_, _, CustomError<_>>("*")(remaining).is_ok() {
return Ok((input, ()));
}
let (remaining, _) = opt(one_of("+-"))(remaining)?;
let (_remaining, _) = verify(anychar, |c| c.is_alphanumeric())(remaining)?;
Ok((input, ()))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn subscript<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,