Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,908 changes: 1,062 additions & 846 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/wasm/src/editor_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ impl EditorHandle {
#[wasm_bindgen(js_name = evaluateMathExpression)]
pub fn evaluate_math_expression(expression: &str) -> Option<f64> {
let value = math_parser::evaluate(expression)
.inspect_err(|err| error!("Math parser error on \"{expression}\": {err}"))
// TODO: Render to html here
.inspect_err(|err| error!("Math parser error on \"{expression}\""))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Parser error diagnostics are dropped from logs before the API collapses failures to None, reducing debuggability of parse regressions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/wasm/src/editor_api.rs, line 931:

<comment>Parser error diagnostics are dropped from logs before the API collapses failures to `None`, reducing debuggability of parse regressions.</comment>

<file context>
@@ -927,9 +927,9 @@ impl EditorHandle {
 	let value = math_parser::evaluate(expression)
-		.inspect_err(|err| error!("Math parser error on \"{expression}\": {err}"))
+		// TODO: Render to html here
+		.inspect_err(|err| error!("Math parser error on \"{expression}\""))
 		.ok()?
-		.0
</file context>

.ok()?
.0
.inspect_err(|err| error!("Math evaluate error on \"{expression}\": {err} "))
.ok()?;
let Some(real) = value.as_real() else {
Expand Down
4 changes: 2 additions & 2 deletions libraries/math-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ description = "Parser for Graphite style mathematics expressions"
license = "MIT OR Apache-2.0"

[dependencies]
pest = "2.7"
pest_derive = "2.7"
thiserror = "2.0"
lazy_static = "1.5"
num-complex = "0.4"
chumsky = { version = "0.10", default-features = false, features = ["std"] }
codespan-reporting = { git = "https://github.com/urisinger/codespan-style-writer.git"}

[dev-dependencies]
criterion = { workspace = true }
Expand Down
10 changes: 8 additions & 2 deletions libraries/math-parser/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ macro_rules! generate_benchmarks {
$(
c.bench_function(concat!("parse ", $input), |b| {
b.iter(|| {
let _ = black_box(ast::Node::try_parse_from_str($input)).unwrap();
let _ = black_box(ast::Node::try_parse_from_str($input));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Parsing benchmark ignores parse errors, allowing parser regressions to be benchmarked silently as error cases.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At libraries/math-parser/benches/bench.rs, line 12:

<comment>Parsing benchmark ignores parse errors, allowing parser regressions to be benchmarked silently as error cases.</comment>

<file context>
@@ -9,15 +9,21 @@ macro_rules! generate_benchmarks {
 				c.bench_function(concat!("parse ", $input), |b| {
 					b.iter(|| {
-						let _ = black_box(ast::Node::try_parse_from_str($input)).unwrap();
+						let _ = black_box(ast::Node::try_parse_from_str($input));
 					});
 				});
</file context>

});
});
)*
}

fn evaluation_bench(c: &mut Criterion) {
$(
let expr = ast::Node::try_parse_from_str($input).unwrap().0;
let expr = match ast::Node::try_parse_from_str($input) {
Ok(expr) => expr,
Err(err) => {
err.print();
panic!(concat!("failed to parse `", $input, "`"));
}
};
let context = EvalContext::default();

c.bench_function(concat!("eval ", $input), |b| {
Expand Down
15 changes: 14 additions & 1 deletion libraries/math-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Unit {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
Float(f64),
Complex(Complex),
Expand All @@ -54,15 +54,27 @@ pub enum BinaryOp {
Add,
Sub,
Mul,
/// Logical AND (nonzero treated as true, returns 1.0 or 0.0)
And,
Div,
/// Logical OR (nonzero treated as true, returns 1.0 or 0.0)
Or,
Modulo,
Pow,
Leq,
Lt,
Geq,
Gt,
Neq,
Eq,
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum UnaryOp {
Neg,
Sqrt,
Fac,
Not,
}

#[derive(Debug, PartialEq)]
Expand All @@ -72,4 +84,5 @@ pub enum Node {
FnCall { name: String, expr: Vec<Node> },
BinOp { lhs: Box<Node>, op: BinaryOp, rhs: Box<Node> },
UnaryOp { expr: Box<Node>, op: UnaryOp },
Conditional { condition: Box<Node>, if_block: Box<Node>, else_block: Box<Node> },
}
Loading
Loading