mod display;
use crate::{
MathError, MathFenced, MathFraction, MathFunction, MathIdentifier, MathMultiScript, MathNumber, MathOperator, MathPhantom,
MathRoot, MathRow, MathSpace, MathSqrt, MathStyle, MathTable, MathText, MathUnderOver,
};
use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MathML {
Root(Box<MathRoot>),
Row(Box<MathRow>),
Space(Box<MathSpace>),
Number(Box<MathNumber>),
Identifier(Box<MathIdentifier>),
Text(Box<MathText>),
Operator(Box<MathOperator>),
MultiScripts(Box<MathMultiScript>),
UnderOver(Box<MathUnderOver>),
Function(Box<MathFunction>),
Sqrt(Box<MathSqrt>),
Frac(Box<MathFraction>),
Phantom(Box<MathPhantom>),
Style(Box<MathStyle>),
Fenced(Box<MathFenced>),
Table(Box<MathTable>),
Undefined(Box<MathError>),
Ampersand,
NewLine,
Nothing,
}
macro_rules! make_mathml {
($($name:ident => $variant:ident),*) => {
$(
impl From<$name> for MathML {
fn from(value: $name) -> Self {
MathML::$variant(Box::new(value))
}
}
)*
};
}
macro_rules! make_number {
($($name:ident),*) => {
$(
impl From<$name> for MathML {
fn from(value: $name) -> Self {
MathML::Number(Box::new(value.into()))
}
}
)*
};
}
impl From<char> for MathML {
fn from(value: char) -> Self {
MathML::identifier(value)
}
}
make_number![i8, i16, i32, i64, i128, isize];
make_number![u8, u16, u32, u64, u128, usize];
make_number![f32, f64];
#[rustfmt::skip]
make_mathml! {
MathRoot => Root,
MathRow => Row,
MathTable => Table,
MathSpace => Space,
MathText => Text,
MathNumber => Number,
MathFunction => Function,
MathUnderOver => UnderOver,
MathIdentifier => Identifier,
MathOperator => Operator,
MathMultiScript => MultiScripts,
MathSqrt => Sqrt,
MathFraction => Frac,
MathPhantom => Phantom,
MathStyle => Style,
MathFenced => Fenced,
MathError => Undefined
}