1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
pub mod attribute;
mod display;
use crate::{
ast::attribute::{Accent, ColumnAlign},
identifiers::MathText,
operators::{MathOperator, MathSqrt, MathUnderOver},
MathFenced, MathFraction, MathIdentifier, MathMultiScript, MathNumber, MathPhantom, MathRoot,
};
use std::fmt::{Display, Formatter};
/// AST node
#[derive(Debug, Clone, PartialEq)]
pub enum MathML {
/// [`<math>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math)
Root(Box<MathRoot>),
/// [`<mn>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mn)
Number(Box<MathNumber>),
/// [`<mi>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mi)
Identifier(Box<MathIdentifier>),
/// [`<ms>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms) / [`<mtext>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtext)
Text(Box<MathText>),
/// [`<mo>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo)
Operator(Box<MathOperator>),
/// [`<msub>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub)
/// / [`<msup>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup)
/// / [`<msubsup>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup)
/// / [`<mmultiscripts>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mmultiscripts)
MultiScripts(Box<MathMultiScript>),
/// [`<munder>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munder) / [`<mover>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mover) / [`<munderover>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover)
UnderOver(Box<MathUnderOver>),
Function(String, Option<Box<MathML>>),
Space(f32),
OverOp(char, Accent, Box<MathML>),
UnderOp(char, Accent, Box<MathML>),
Sqrt(Box<MathSqrt>),
Frac(Box<MathFraction>),
Phantom(Box<MathPhantom>),
Row(Vec<MathML>),
Fenced(Box<MathFenced>),
StrechedOp(bool, String),
SizedParen {
size: &'static str,
paren: &'static str,
},
Matrix(Vec<MathML>, ColumnAlign),
Ampersand,
NewLine,
Slashed(Box<MathML>),
Style(Option<DisplayStyle>, Box<MathML>),
Undefined(String),
}
/// display style
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DisplayStyle {
Block,
Inline,
}
macro_rules! make_mathml {
($($name:ident => $variant:ident),*) => {
$(
impl From<$name> for MathML {
fn from(value: $name) -> Self {
MathML::$variant(Box::new(value))
}
}
)*
};
}
#[rustfmt::skip]
make_mathml! {
MathRoot => Root,
MathNumber => Number,
MathIdentifier => Identifier,
MathOperator => Operator,
MathMultiScript => MultiScripts,
MathSqrt => Sqrt,
MathFraction => Frac,
MathPhantom => Phantom
}