diff --git a/src/interpreter.rs b/src/interpreter.rs index 685b85d..c057260 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -119,6 +119,14 @@ impl Interpreter { self.error("Unsupported data type for the `var` argument, must be a string"); } }, + "ref" => match value { + Value::String(value) => { + return self.variable_reference(value); + } + _ => { + self.error("Unsupported data type for the `ref` argument, must be a string"); + } + }, "isExist" => match value { Value::String(value) => { return Value::Bool(self.var_exists(value)); @@ -437,6 +445,18 @@ impl Interpreter { } } + fn variable_reference(&mut self, name: &String) -> Value { + if self.var_exists(name) { + return json!({ "var": name }); + } else { + self.error(&format!( + "The variable {} does not exist, the reference is invalid", + name + )); + } + Value::Null + } + fn calc(&mut self, value: &Vec) -> Value { let op1 = &value[0]; let operation = &value[1];