Repository: CSML-by-Clevy/csml-engine (rust)

Issue:
.floor() does does not floor after parentheses
**Describe the bug**
The floor method does not do anything when applied to a float within parentheses

**To Reproduce**
do r = (100 / 3).floor()
// 33.33333333

**Expected behavior**
It should return 33

**Additional context**
I havent tried other float methods


Pull request description:
fix parentheses operations
Fixes #313 #312 

Patch:
diff --git a/csml_interpreter/src/interpreter/variable_handler/expr_to_literal.rs b/csml_interpreter/src/interpreter/variable_handler/expr_to_literal.rs
index 6a32d1ce..95bb30e7 100644
--- a/csml_interpreter/src/interpreter/variable_handler/expr_to_literal.rs
+++ b/csml_interpreter/src/interpreter/variable_handler/expr_to_literal.rs
@@ -117,7 +117,8 @@ pub fn expr_to_literal(
             exec_path_literal(&mut literal, condition, path, data, msg_data, sender)
         }
         Expr::InfixExpr(infix, exp_1, exp_2) => {
-            evaluate_condition(infix, exp_1, exp_2, data, msg_data, sender)
+            let mut literal = evaluate_condition(infix, exp_1, exp_2, data, msg_data, sender)?;
+            exec_path_literal(&mut literal, condition, path, data, msg_data, sender)
         }
         Expr::LitExpr { literal, .. } => {
             let mut new_value = exec_path_literal(
diff --git a/csml_interpreter/src/interpreter/variable_handler/operations.rs b/csml_interpreter/src/interpreter/variable_handler/operations.rs
index 8188ad9f..77353880 100644
--- a/csml_interpreter/src/interpreter/variable_handler/operations.rs
+++ b/csml_interpreter/src/interpreter/variable_handler/operations.rs
@@ -1,6 +1,6 @@
 use crate::data::position::Position;
 use crate::data::primitive::boolean::PrimitiveBoolean;
-use crate::data::{ast::Infix, Literal};
+use crate::data::{ast::{Infix}, Literal};
 use crate::error_format::{gen_error_info, ErrorInfo};
 use crate::interpreter::variable_handler::match_literals::match_obj;
 
diff --git a/csml_interpreter/src/parser/operator/mod.rs b/csml_interpreter/src/parser/operator/mod.rs
index e31a040f..99892318 100644
--- a/csml_interpreter/src/parser/operator/mod.rs
+++ b/csml_interpreter/src/parser/operator/mod.rs
@@ -1,5 +1,5 @@
 pub mod parse_operator;
+pub mod tools;
 
 pub use parse_operator::parse_operator;
 
-mod tools;
diff --git a/csml_interpreter/src/parser/parse_var_types.rs b/csml_interpreter/src/parser/parse_var_types.rs
index 2cbb1b9c..9846d6e0 100644
--- a/csml_interpreter/src/parser/parse_var_types.rs
+++ b/csml_interpreter/src/parser/parse_var_types.rs
@@ -1,7 +1,7 @@
-use crate::data::{ast::*, tokens::*};
+use crate::data::{ast::*, tokens::*, primitive::PrimitiveInt};
 use crate::error_format::{gen_nom_failure, ERROR_RIGHT_BRACKET};
 use crate::parser::{
-    operator::parse_operator,
+    operator::{parse_operator, tools::parse_item_operator},
     parse_built_in::parse_built_in,
     parse_closure::parse_closure,
     parse_comments::comment,
@@ -32,11 +32,22 @@ fn parse_condition_group<'a, E: ParseError<Span<'a>>>(s: Span<'a>) -> IResult<Sp
 where
     E: ParseError<Span<'a>>,
 {
-    delimited(
-        preceded(comment, tag(L_PAREN)),
-        parse_operator,
-        parse_r_parentheses,
-    )(s)
+    let (s, interval) = get_interval(s)?;
+
+    let (s, opt) = opt(preceded(comment, parse_item_operator))(s)?;
+    let (s, expr) =  delimited(
+            preceded(comment, tag(L_PAREN)),
+            parse_operator,
+            parse_r_parentheses,
+    )(s)?;
+
+    match opt {
+        Some(infix) => {
+            let zero = Expr::LitExpr{literal: PrimitiveInt::get_literal(0,interval), in_in_substring: false};
+            Ok((s, Expr::InfixExpr(infix, Box::new(zero), Box::new(expr))))
+        },
+        None => Ok((s, expr))
+    }
 }
 
 fn parse_assignation_without_path<'a, E>(s: Span<'a>) -> IResult<Span<'a>, Expr, E>


Test patch:
diff --git a/csml_interpreter/CSML/basic_test/numerical_operation/addition.csml b/csml_interpreter/CSML/basic_test/numerical_operation/addition.csml
index fbe5e31d..04865dc6 100644
--- a/csml_interpreter/CSML/basic_test/numerical_operation/addition.csml
+++ b/csml_interpreter/CSML/basic_test/numerical_operation/addition.csml
@@ -228,4 +228,10 @@ addition_string_step_5:
 
 addition_string_step_6:
     say "1" + "1"
-    goto end
\ No newline at end of file
+    goto end
+
+addition_parentheses_step_1:
+    do a = 1.1
+    do b = 4.4
+
+    say -(a + b)
diff --git a/csml_interpreter/CSML/basic_test/stdlib/number.csml b/csml_interpreter/CSML/basic_test/stdlib/number.csml
index 226aa00c..d82394f8 100644
--- a/csml_interpreter/CSML/basic_test/stdlib/number.csml
+++ b/csml_interpreter/CSML/basic_test/stdlib/number.csml
@@ -51,6 +51,12 @@ float_1:
 
     goto end
 
+float_2:
+
+    say (100 / 3).floor()
+
+    goto end
+
 string_0:
     use "42" as string
 
diff --git a/csml_interpreter/tests/addition.rs b/csml_interpreter/tests/addition.rs
index eb1fa7c1..02b00a10 100644
--- a/csml_interpreter/tests/addition.rs
+++ b/csml_interpreter/tests/addition.rs
@@ -1574,3 +1574,34 @@ fn addition_string_step_6() {
 
     assert_eq!(v1, v2)
 }
+
+/////////////////////////////////////////////////////////////////////////////////
+/// PARENTHESES
+////////////////////////////////////////////////////////////////////////////////
+
+#[test]
+fn addition_parentheses_step_1() {
+    let data = r#"{
+        "memories":[
+        ],
+        "messages":[
+            {"content":{"text": "-5.5"}, "content_type":"text"}
+        ]}"#;
+    let msg = format_message(
+        Event::new("payload", "", serde_json::json!({})),
+        Context::new(
+            HashMap::new(),
+            HashMap::new(),
+            None,
+            None,
+            "addition_parentheses_step_1",
+            "flow",
+        ),
+        "CSML/basic_test/numerical_operation/addition.csml",
+    );
+
+    let v1: Value = message_to_json_value(msg);
+    let v2: Value = serde_json::from_str(data).unwrap();
+
+    assert_eq!(v1, v2)
+}
\ No newline at end of file
diff --git a/csml_interpreter/tests/number.rs b/csml_interpreter/tests/number.rs
index e4ccf0a2..594432c8 100644
--- a/csml_interpreter/tests/number.rs
+++ b/csml_interpreter/tests/number.rs
@@ -128,6 +128,33 @@ fn float_step_1() {
     assert_eq!(v1, v2)
 }
 
+#[test]
+fn float_step_2() {
+    let data = r#"{
+        "memories":[
+        ],
+        "messages":[
+            {"content":{"text": "33"}, "content_type":"text"}
+        ]}"#;
+    let msg = format_message(
+        Event::new("payload", "", serde_json::json!({})),
+        Context::new(
+            HashMap::new(),
+            HashMap::new(),
+            None,
+            None,
+            "float_2",
+            "flow",
+        ),
+        "CSML/basic_test/stdlib/number.csml",
+    );
+
+    let v1: Value = message_to_json_value(msg);
+    let v2: Value = serde_json::from_str(data).unwrap();
+
+    assert_eq!(v1, v2)
+}
+
 #[test]
 fn string_step_0() {
     let data = r#"{