From f1259a6b1b701937aee1a2094f3eefda69e01b7d Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 14 Aug 2022 23:32:54 +0300 Subject: [PATCH] feat: reference variables --- src/interpreter.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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];