Skip to content

Commit 96e82f8

Browse files
committed
always box
1 parent b420dbc commit 96e82f8

1 file changed

Lines changed: 11 additions & 27 deletions

File tree

libraries/math-parser/src/parser.rs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ use thiserror::Error;
1212
pub enum ParseError<'src> {
1313
#[error("Syntax error(s): {0:#?}")]
1414
Syntax(Vec<Rich<'src, char>>),
15-
#[error("nig")]
16-
Nigga(),
17-
}
18-
19-
#[cfg(not(debug_assertions))] // In release build: skip boxing
20-
macro_rules! maybe_boxed {
21-
($p:expr) => {
22-
$p
23-
};
24-
}
25-
26-
#[cfg(debug_assertions)] // In debug build: box for faster compilation
27-
macro_rules! maybe_boxed {
28-
($p:expr) => {
29-
$p.boxed()
30-
};
3115
}
3216

3317
impl Node {
@@ -98,7 +82,7 @@ pub fn chumsky_parser<'a>() -> impl Parser<'a, &'a str, Node, chumsky::extra::Er
9882
else_block: Box::new(else_b),
9983
});
10084

101-
let atom = maybe_boxed!(choice((conditional, float, constant, call, parens, var)));
85+
let atom = choice((conditional, float, constant, call, parens, var)).boxed();
10286

10387
let unary = choice((just('-').to(UnaryOp::Neg), just("sqrt").to(UnaryOp::Sqrt)))
10488
.padded()
@@ -111,16 +95,16 @@ pub fn chumsky_parser<'a>() -> impl Parser<'a, &'a str, Node, chumsky::extra::Er
11195
rhs: Box::new(rhs),
11296
});
11397

114-
let product = maybe_boxed!(
115-
pow.clone()
116-
.foldl(choice((just('*').to(BinaryOp::Mul), just('/').to(BinaryOp::Div))).padded().then(pow).repeated(), |lhs, (op, rhs)| {
117-
Node::BinOp {
118-
lhs: Box::new(lhs),
119-
op,
120-
rhs: Box::new(rhs),
121-
}
122-
})
123-
);
98+
let product = pow
99+
.clone()
100+
.foldl(choice((just('*').to(BinaryOp::Mul), just('/').to(BinaryOp::Div))).padded().then(pow).repeated(), |lhs, (op, rhs)| {
101+
Node::BinOp {
102+
lhs: Box::new(lhs),
103+
op,
104+
rhs: Box::new(rhs),
105+
}
106+
})
107+
.boxed();
124108

125109
let sum = product.clone().foldl(
126110
choice((just('+').to(BinaryOp::Add), just('-').to(BinaryOp::Sub))).padded().then(product).repeated(),

0 commit comments

Comments
 (0)