protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.END_ARG_ARRAY); Utils.CheckNotEnd(script, m_name); List <Variable> arrayIndices = Utils.GetArrayIndices(ref varName); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable currentValue = func.GetValue(script); Variable element = currentValue; // 2b. Special case for an array. if (arrayIndices.Count > 0)// array element { element = Utils.ExtractArrayElement(currentValue, arrayIndices); script.MoveForwardIf(Constants.END_ARRAY); } // 3. Convert type to string. string type = Constants.TypeToString(element.Type); script.MoveForwardIf(Constants.END_ARG, Constants.SPACE); Variable newValue = new Variable(type); return(newValue); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY); Utils.CheckNotEnd(script, Constants.CONTAINS); // 2. Get the current value of the variable. List <Variable> arrayIndices = Utils.GetArrayIndices(ref varName); ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable currentValue = func.GetValue(script); // 2b. Special dealings with arrays: Variable query = arrayIndices.Count > 0 ? Utils.ExtractArrayElement(currentValue, arrayIndices) : currentValue; // 3. Get the value to be looked for. Variable searchValue = Utils.GetItem(script); Utils.CheckNotEnd(script, Constants.CONTAINS); // 4. Check if the value to search for exists. bool exists = query.Exists(searchValue, true /* notEmpty */); script.MoveBackIf(Constants.START_GROUP); return(new Variable(exists)); }
public static Variable GetItem(ParsingScript script, bool eatLast = true) { script.MoveForwardIf(Constants.NEXT_ARG, Constants.SPACE); Utils.CheckNotEnd(script); bool inQuotes = script.Current == Constants.QUOTE; if (script.Current == Constants.START_GROUP) { // We are extracting a list between curly braces. script.Forward(); // Skip the first brace. bool isList = true; Variable value = new Variable(); value.Tuple = GetArgs(script, Constants.START_GROUP, Constants.END_GROUP, out isList); return(value); } // A variable, a function, or a number. Variable var = script.Execute(Constants.NEXT_OR_END_ARRAY); //value = var.Clone(); if (inQuotes) { script.MoveForwardIf(Constants.QUOTE); } if (eatLast) { script.MoveForwardIf(Constants.END_ARG, Constants.SPACE); } return(var); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY); Utils.CheckNotEnd(script, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable currentValue = func.GetValue(script); Utils.CheckArray(currentValue, varName); // 3. Get the variable to remove. Variable item = Utils.GetItem(script); Utils.CheckNonNegativeInt(item); currentValue.Tuple.RemoveAt(item.AsInt()); ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(currentValue)); return(Variable.EmptyInstance); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.END_ARG_ARRAY); Utils.CheckNotEnd(script, m_name); List <Variable> arrayIndices = Utils.GetArrayIndices(ref varName); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable currentValue = func.GetValue(script); Variable element = currentValue; // 2b. Special case for an array. if (arrayIndices.Count > 0)// array element { element = Utils.ExtractArrayElement(currentValue, arrayIndices); script.MoveForwardIf(Constants.END_ARRAY); } // 3. Take either the length of the underlying tuple or // string part if it is defined, // or the numerical part converted to a string otherwise. int size = element.Type == Variable.VarType.ARRAY ? element.Tuple.Count : element.AsString().Length; script.MoveForwardIf(Constants.END_ARG, Constants.SPACE); Variable newValue = new Variable(size); return(newValue); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY); Utils.CheckNotEnd(script, Constants.CONTAINS); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable currentValue = func.GetValue(script); // 3. Get the variable to add. Variable item = Utils.GetItem(script); // 4. Add it to the tuple. currentValue.AddVariable(item); ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(currentValue)); return(currentValue); }