protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetVariable(varName, script); Variable currentValue = func.GetValue(script); // 3. Get the value to be added or appended. Variable newValue = Utils.GetItem(script); // 4. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg1 = currentValue.AsString(); string arg2 = newValue.AsString(); // 5. The variable becomes a string after adding a string to it. newValue.Reset(); newValue.String = arg1 + arg2; ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(newValue), script); return(newValue); }
static ParserFunction GetObjectFunction(string name, ParsingScript script) { if (script.CurrentClass != null && script.CurrentClass.Name == name) { script.Backward(name.Length + 1); return(new FunctionCreator()); } if (script.ClassInstance != null && (script.ClassInstance.PropertyExists(name) || script.ClassInstance.FunctionExists(name))) { name = script.ClassInstance.InstanceName + "." + name; } //int ind = name.LastIndexOf('.'); int ind = name.IndexOf('.'); if (ind <= 0) { return(null); } string baseName = name.Substring(0, ind); if (s_namespaces.ContainsKey(baseName)) { int ind2 = name.IndexOf('.', ind + 1); if (ind2 > 0) { ind = ind2; baseName = name.Substring(0, ind); } } string prop = name.Substring(ind + 1); ParserFunction pf = ParserFunction.GetFromNamespace(prop, baseName, script); if (pf != null) { return(pf); } pf = ParserFunction.GetVariable(baseName, script, true); if (pf == null || !(pf is GetVarFunction)) { pf = ParserFunction.GetFunction(baseName, script); if (pf == null) { pf = Utils.ExtractArrayElement(baseName); } } GetVarFunction varFunc = pf as GetVarFunction; if (varFunc == null) { return(null); } varFunc.PropertyName = prop; return(varFunc); }
public static async Task <Variable> GetVariableAsync(string varName, ParsingScript script, bool testNull = true) { ParserFunction func = ParserFunction.GetVariable(varName, script); if (!testNull && func == null) { return(null); } Utils.CheckNotNull(varName, func, script); Variable varValue = await func.GetValueAsync(script); Utils.CheckNotNull(varValue, varName, script); return(varValue); }
static ParserFunction GetArrayFunction(string name, ParsingScript script, string action) { int arrayStart = name.IndexOf(Constants.START_ARRAY); if (arrayStart < 0) { return(null); } if (arrayStart == 0) { Variable arr = Utils.ProcessArrayMap(new ParsingScript(name)); return(new GetVarFunction(arr)); } string arrayName = name; int delta = 0; List <Variable> arrayIndices = Utils.GetArrayIndices(script, arrayName, delta, (string arr, int del) => { arrayName = arr; delta = del; }); if (arrayIndices.Count == 0) { return(null); } ParserFunction pf = ParserFunction.GetVariable(arrayName, script); GetVarFunction varFunc = pf as GetVarFunction; if (varFunc == null) { return(null); } // we temporarily backtrack for the processing script.Backward(name.Length - arrayStart - 1); script.Backward(action != null ? action.Length : 0); // delta shows us how manxy chars we need to advance forward in GetVarFunction() delta -= arrayName.Length; delta += action != null ? action.Length : 0; varFunc.Indices = arrayIndices; varFunc.Delta = delta; return(varFunc); }