Skip to content

Commit b4fe1bf

Browse files
Compute parentheses expressions (!39)
1 parent c21f741 commit b4fe1bf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* enhance the `compute_expression` rule by processing parentheses expressions ([!39](https://gitlab.com/seaofvoices/darklua/-/merge_requests/39))
56
* add rule to convert index expression to field expression ([!36](https://gitlab.com/seaofvoices/darklua/-/merge_requests/36))
67
* add logging to time processing steps ([!35](https://gitlab.com/seaofvoices/darklua/-/merge_requests/35))
78
* add rule to remove spaces ([!34](https://gitlab.com/seaofvoices/darklua/-/merge_requests/34))

src/process/evaluator/mod.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ impl Evaluator {
3131
Expression::True(_) => LuaValue::True,
3232
Expression::Binary(binary) => self.evaluate_binary(binary),
3333
Expression::Unary(unary) => self.evaluate_unary(unary),
34-
_ => LuaValue::Unknown,
34+
Expression::Parenthese(parenthese) => {
35+
// when the evaluator will be able to manage tuples, keep only the first element
36+
// of the tuple here (or coerce the tuple to `nil` if it is empty)
37+
self.evaluate(parenthese.inner_expression())
38+
}
39+
Expression::Call(_)
40+
| Expression::Field(_)
41+
| Expression::Identifier(_)
42+
| Expression::Index(_)
43+
| Expression::VariableArguments(_) => LuaValue::Unknown,
3544
}
3645
}
3746

@@ -277,8 +286,15 @@ mod test {
277286
true_expression(Expression::from(true)) => LuaValue::True,
278287
false_expression(Expression::from(false)) => LuaValue::False,
279288
nil_expression(Expression::nil()) => LuaValue::Nil,
280-
number_expression(Expression::Number(DecimalNumber::new(0.0).into())) => LuaValue::Number(0.0),
289+
number_expression(DecimalNumber::new(0.0)) => LuaValue::Number(0.0),
281290
string_expression(StringExpression::from_value("foo")) => LuaValue::String("foo".to_owned()),
291+
true_wrapped_in_parens(ParentheseExpression::new(true)) => LuaValue::True,
292+
false_wrapped_in_parens(ParentheseExpression::new(false)) => LuaValue::False,
293+
nil_wrapped_in_parens(ParentheseExpression::new(Expression::nil())) => LuaValue::Nil,
294+
number_wrapped_in_parens(ParentheseExpression::new(DecimalNumber::new(0.0)))
295+
=> LuaValue::Number(0.0),
296+
string_wrapped_in_parens(ParentheseExpression::new(StringExpression::from_value("foo")))
297+
=> LuaValue::String("foo".to_owned()),
282298
table_expression(TableExpression::default()) => LuaValue::Table
283299
);
284300

0 commit comments

Comments
 (0)