#![forbid(unsafe_code)]
#![warn(clippy::pedantic, missing_docs)]
mod ast;
mod block;
mod inline;
mod tokens;
pub use asciimath_parser::tree::Expression;
pub use emojis::SkinTone;
use inline::Mapper;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(clippy::struct_excessive_bools)]
pub struct Conf {
pub strip_brackets: bool,
pub vulgar_fracs: bool,
pub script_fracs: bool,
pub skin_tone: SkinTone,
pub block: bool,
}
impl Default for Conf {
fn default() -> Self {
Conf {
strip_brackets: true,
vulgar_fracs: true,
script_fracs: true,
skin_tone: SkinTone::Default,
block: false,
}
}
}
impl Conf {
#[must_use]
pub fn parse(self, inp: &str) -> Asciimath<'_> {
Asciimath {
conf: self,
expr: tokens::parse(inp),
}
}
}
#[derive(Debug, Clone)]
pub struct Asciimath<'a> {
pub conf: Conf,
pub expr: Expression<'a>,
}
impl fmt::Display for Asciimath<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.conf.block {
let block = self.conf.block_expression(&self.expr);
write!(f, "{block}")
} else {
self.conf.inline_expression(&self.expr, &mut Mapper::new(f))
}
}
}
#[must_use]
pub fn parse_unicode(inp: &str) -> Asciimath<'_> {
Conf::default().parse(inp)
}