public string Eval(Scope previous_scope, ContextOptions options, List <string> diagnostics = null) { Expression tree = _parse_result.RootExpression; tree.Print(); ScriptScope script_scope = new ScriptScope(previous_scope, _script); if (_parse_result.Diagnostics.Length != 0) { if (diagnostics != null) { foreach (var diag in _parse_result.Diagnostics) { diagnostics.Add(diag.ToString()); } } else { throw new Exception(_parse_result.Diagnostics.Join("\n")); } } string res = Interpreters.Execute(tree, script_scope).ResultValue.GetStringValue(); if (options.DEBUG_EXECUTION) { Console.ReadLine(); } return(res); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 2) { throw new WrongParameterCountException(this, expected: 2, actual: parameters.Length); } FinalExpression param_needle = parameters [0].EvaluatedValue; FinalExpression param_haystack = parameters [0].EvaluatedValue; if (param_haystack is ArrayPointerExpression array_pointer) { ArrayKey needle = param_needle.GetStringValue(); Log.Debug($"check if element is in array: {needle}"); return(new Result(new BoolExpression(array_pointer.Array.GetAll().Any(item => { return Interpreters.Execute(new BinaryExpression(param_needle, item.Value, BinaryOp.EQUAL), function_scope).ResultValue.GetBoolValue(); })))); } else { return(new Result(new BoolExpression(false))); } }