From 47c606d78ee0e28c06b29cec77adec223041c7a1 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 26 Feb 2024 17:56:37 -0600 Subject: [PATCH] reverting commits --- skema/skema-rs/mathml/src/ast.rs | 33 +---------- .../mathml/src/parsers/generic_mathml.rs | 3 +- .../mathml/src/parsers/interpreted_mathml.rs | 42 +++++++++----- .../src/parsers/math_expression_tree.rs | 58 +++++++++++++++++-- 4 files changed, 84 insertions(+), 52 deletions(-) diff --git a/skema/skema-rs/mathml/src/ast.rs b/skema/skema-rs/mathml/src/ast.rs index 461d060342f..5cc00616c5f 100644 --- a/skema/skema-rs/mathml/src/ast.rs +++ b/skema/skema-rs/mathml/src/ast.rs @@ -202,7 +202,7 @@ impl fmt::Display for MathExpression { MathExpression::Msub(base, subscript) => { write!(f, "{base}_{{{subscript}}}") } - MathExpression::Msubsup(base, subscript, superscript) => { + MathExpression::Msubsup(base, subscript,superscript)=>{ write!(f, "{base}_{{{subscript}}}^{{{superscript}}}") } MathExpression::Mo(op) => { @@ -222,37 +222,6 @@ impl fmt::Display for MathExpression { write!(f, "{:?}", base)?; write!(f, "{superscript:?}") } - MathExpression::Mtext(text) => write!(f, "{}", text), - MathExpression::SummationMath(SummationMath { op, func }) => { - write!(f, "{op}")?; - write!(f, "{func}") - } - MathExpression::HatComp(HatComp { op, comp }) => { - write!(f, "{op}")?; - write!(f, "{comp}") - } - MathExpression::Integral(Integral { - op, - integrand, - integration_variable, - }) => { - write!(f, "{op}")?; - write!(f, "{integrand}")?; - write!(f, "{integration_variable}") - } - MathExpression::LaplacianComp(LaplacianComp { op, comp }) => { - write!(f, "{op}(")?; - write!(f, "{comp})") - } - MathExpression::SurfaceIntegral(row) => { - write!(f, "{row})") - } - MathExpression::DownArrow(DownArrow { sub, sup, comp }) => match (sub, sup) { - (Some(low), Some(up)) => write!(f, "{comp}↓_{{{low}}}^{{{up}}}"), - (Some(low), None) => write!(f, "{comp}↓_{{{low}}}"), - (None, Some(up)) => write!(f, "{comp}↓^{{{up}}}"), - (None, None) => write!(f, "{comp}↓"), - }, expression => write!(f, "{expression:?}"), } } diff --git a/skema/skema-rs/mathml/src/parsers/generic_mathml.rs b/skema/skema-rs/mathml/src/parsers/generic_mathml.rs index 8fcc4602712..5c6adcb5fff 100644 --- a/skema/skema-rs/mathml/src/parsers/generic_mathml.rs +++ b/skema/skema-rs/mathml/src/parsers/generic_mathml.rs @@ -245,6 +245,7 @@ pub fn grad(input: Span) -> IResult { let (s, op) = value(Operator::Grad, alt((ws(tag("∇")), ws(tag("∇")))))(input)?; Ok((s, op)) } + pub fn dot(input: Span) -> IResult { let (s, op) = value(Operator::Dot, alt((ws(tag("⋅")), ws(tag("⋅")))))(input)?; Ok((s, op)) @@ -365,7 +366,7 @@ pub fn msubsup(input: Span) -> IResult { } //Text -pub fn mtext(input: Span) -> IResult { +fn mtext(input: Span) -> IResult { let (s, element) = elem0!("mtext")(input)?; Ok((s, Mtext(element.trim().to_string()))) } diff --git a/skema/skema-rs/mathml/src/parsers/interpreted_mathml.rs b/skema/skema-rs/mathml/src/parsers/interpreted_mathml.rs index 8f9ac2f8f48..4287627412a 100644 --- a/skema/skema-rs/mathml/src/parsers/interpreted_mathml.rs +++ b/skema/skema-rs/mathml/src/parsers/interpreted_mathml.rs @@ -11,9 +11,9 @@ use crate::{ SummationMath, Type, }, parsers::generic_mathml::{ - add, attribute, cross, divide, dot, elem_many0, equals, etag, lparen, mean, mi, mn, msub, - msubsup, mtext, multiply, rparen, stag, subtract, tag_parser, vector, ws, xml_declaration, - IResult, ParseError, Span, + add, attribute, dot, elem_many0, equals, etag, grad, lparen, mean, mi, mn, msqrt, msub, + msubsup, multiply, rparen, stag, subtract, tag_parser, ws, xml_declaration, IResult, + ParseError, Span, }, }; @@ -1725,18 +1725,30 @@ pub fn math_expression(input: Span) -> IResult { func_of: None, }) }), - alt(( - absolute, - sqrt, - map(operator, MathExpression::Mo), - map(gradient, MathExpression::Mo), - mn, - msub, - superscript, - mfrac, - mtext, - over_term, - )), + map( + grad_func, + |( + op, + Ci { + r#type, + content, + func_of, + }, + )| { + MathExpression::Differential(Differential { + diff: Box::new(MathExpression::Mo(op)), + func: Box::new(MathExpression::Ci(Ci { + r#type, + content, + func_of, + })), + }) + }, + ), + absolute, + map(operator, MathExpression::Mo), + map(gradient, MathExpression::Mo), + alt((mn, msub, superscript, msqrt, mfrac, over_term)), map(mrow, MathExpression::Mrow), msubsup, )))(input) diff --git a/skema/skema-rs/mathml/src/parsers/math_expression_tree.rs b/skema/skema-rs/mathml/src/parsers/math_expression_tree.rs index 5aee376df84..c7cc4fc5da5 100644 --- a/skema/skema-rs/mathml/src/parsers/math_expression_tree.rs +++ b/skema/skema-rs/mathml/src/parsers/math_expression_tree.rs @@ -1348,7 +1348,14 @@ pub fn preprocess_mathml_for_to_latex(input: &str) -> String { .replace_all(&no_newlines, "><") .to_string(); - no_spaces.to_string() + let new_no_spaces = no_spaces.replace(" ", ""); + + // Replace with + let replaced_str = new_no_spaces + .replace(r#""#, "") + .to_string(); + + replaced_str } #[test] @@ -2391,6 +2398,7 @@ fn new_test_halfar_whitespace() { "; let exp = input.parse::().unwrap(); let s_exp = exp.to_string(); + println!("s_exp={:?}", s_exp); assert_eq!( s_exp, "(= t_{0} (* (* (/ 1 (* 18 Γ)) (^ (/ 7 4) 3)) (/ R_{0}^{4} H_{0}^{7})))" @@ -2398,11 +2406,53 @@ fn new_test_halfar_whitespace() { } #[test] -fn test_equation_with_mtext() { - let input = "Lreg=Ld1+Ld2"; +fn new_test_halfar_whitespace() { + let input = " + + + t + 0 + + = + + 1 + + 18 + Γ + + + + + ( + + 7 + 4 + + ) + + 3 + + + + R + 0 + 4 + + + H + 0 + 7 + + + + "; let exp = input.parse::().unwrap(); let s_exp = exp.to_string(); - assert_eq!(s_exp, "(= L_{reg} (+ L_{d1} L_{d2}))"); + println!("s_exp={:?}", s_exp); + assert_eq!( + s_exp, + "(= t_{0} (* (* (/ 1 (* 18 Γ)) (^ (/ 7 4) 3)) (/ R_{0}^{4} H_{0}^{7})))" + ); } #[test]