use super::shared::{opt_span, GrammarSpan};
use crate::grammar::inlines::inline_math;
use crate::parser::ast::{Node, NodeKind};
use nom::IResult;
pub fn parse_inline_math(input: GrammarSpan) -> IResult<GrammarSpan, Node> {
let (rest, content_span) = inline_math(input)?;
let node = Node {
kind: NodeKind::InlineMath {
content: content_span.fragment().to_string(),
},
span: opt_span(content_span),
children: Vec::new(),
};
Ok((rest, node))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke_test_parse_inline_math() {
let input = GrammarSpan::new("$E = mc^2$ text");
let result = parse_inline_math(input);
assert!(result.is_ok());
let (_, node) = result.unwrap();
match node.kind {
NodeKind::InlineMath { content } => {
assert_eq!(content, "E = mc^2");
}
_ => panic!("Expected InlineMath node"),
}
}
}