use std::{fmt::Display, str::FromStr};
use winnow::{
ModalResult, Parser,
error::{ContextError, StrContext},
stream::AsChar,
token::take_till,
};
use crate::roles::SphinxType;
#[derive(Debug, PartialEq)]
pub enum MathRole {
Numref,
}
impl Display for MathRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
MathRole::Numref => "numref",
})
}
}
impl FromStr for MathRole {
type Err = ContextError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s {
"numref" => Ok(MathRole::Numref),
_ => Err(ContextError::new()),
}
}
}
pub(crate) fn math_role(input: &mut &str) -> ModalResult<SphinxType> {
let role = take_till(1.., AsChar::is_space)
.context(StrContext::Label("Math Role"))
.parse_to()
.parse_next(input)?;
Ok(SphinxType::Mathematics(role))
}