difftreelog
refactor(ir) drop Parened expr
in: master
4 files changed
crates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/async_import.rs
+++ b/crates/jrsonnet-evaluator/src/async_import.rs
@@ -211,7 +211,7 @@
find_imports(expr, out);
}
}
- Expr::Parened(expr) | Expr::UnaryOp(_, expr) | Expr::ErrorStmt(expr) => {
+ Expr::UnaryOp(_, expr) | Expr::ErrorStmt(expr) => {
find_imports(expr, out);
}
}
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -53,7 +53,6 @@
| Expr::Num(_)
| Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,
Expr::Arr(a) => a.iter().all(is_trivial),
- Expr::Parened(e) => is_trivial(e),
_ => false,
}
}
@@ -76,7 +75,6 @@
.collect(),
))
}
- Expr::Parened(e) => evaluate_trivial(e)?,
_ => return None,
})
}
@@ -414,7 +412,6 @@
Literal(LiteralType::True) => Val::Bool(true),
Literal(LiteralType::False) => Val::Bool(false),
Literal(LiteralType::Null) => Val::Null,
- Parened(e) => evaluate(ctx, e)?,
Str(v) => Val::string(v.clone()),
Num(v) => Val::try_num(*v)?,
// I have tried to remove special behavior from super by implementing standalone-super
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth336 /// Object extension: var1 {b: 2}336 /// Object extension: var1 {b: 2}337 ObjExtend(LocExpr, ObjBody),337 ObjExtend(LocExpr, ObjBody),338339 /// (obj)340 Parened(LocExpr),341338342 /// -2339 /// -2343 UnaryOp(UnaryOpType, LocExpr),340 UnaryOp(UnaryOpType, LocExpr),crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -313,6 +313,7 @@
use UnaryOpType::*;
rule expr(s: &ParserSettings) -> LocExpr
= precedence! {
+ "(" _ e:expr(s) _ ")" {e}
start:position!() v:@ end:position!() { LocExpr::new(v, Span(s.source.clone(), start as u32, end as u32)) }
--
a:(@) _ binop(<"||">) _ b:@ {expr_bin!(a Or b)}
@@ -359,7 +360,6 @@
a:(@) _ "{" _ body:objinside(s) _ "}" {Expr::ObjExtend(a, body)}
--
e:expr_basic(s) {e}
- "(" _ e:expr(s) _ ")" {Expr::Parened(e)}
}
pub rule index_part(s: &ParserSettings) -> IndexPart
= n:("?" _ ensure_null_coaelse())? "." _ value:id_loc(s) {IndexPart {
@@ -559,25 +559,21 @@
el!(Expr::Num(2.0), 0, 1),
Add,
el!(
- Expr::Parened(el!(
- Expr::BinaryOp(
- el!(Expr::Num(2.0), 3, 4),
- Add,
- el!(
- Expr::BinaryOp(
- el!(Expr::Num(2.0), 5, 6),
- Mul,
- el!(Expr::Num(2.0), 7, 8),
- ),
- 5,
- 8
+ Expr::BinaryOp(
+ el!(Expr::Num(2.0), 3, 4),
+ Add,
+ el!(
+ Expr::BinaryOp(
+ el!(Expr::Num(2.0), 5, 6),
+ Mul,
+ el!(Expr::Num(2.0), 7, 8),
),
+ 5,
+ 8
),
- 3,
- 8
- )),
- 2,
- 9
+ ),
+ 3,
+ 8
),
),
0,