static void NormalizeValue(ParserFunction function) { GetVarFunction gvf = function as GetVarFunction; if (gvf != null) { gvf.Value.CurrentAssign = ""; } }
public static bool TryAddToNamespace(string name, string nameSpace, Variable varValue) { StackLevel level; if (string.IsNullOrWhiteSpace(nameSpace) || !s_namespaces.TryGetValue(nameSpace, out level)) { return(false); } var vars = level.Variables; vars[name] = new GetVarFunction(varValue); return(true); }
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); }
public static void AddGlobalOrLocalVariable(string name, GetVarFunction function, ParsingScript script = null, bool localIfPossible = false) { name = Constants.ConvertName(name); if (Constants.CheckReserved(name)) { Utils.ThrowErrorMsg(name + " is a reserved name.", script, name); } bool globalOnly = !localIfPossible && !LocalNameExists(name); Dictionary <string, ParserFunction> lastLevel = GetLastLevel(); if (!globalOnly && lastLevel != null && s_lastExecutionLevel.IsNamespace && !string.IsNullOrWhiteSpace(s_namespace)) { name = s_namespacePrefix + name; } function.Name = Constants.GetRealName(name); function.Value.ParamName = function.Name; if (!globalOnly && !localIfPossible && script != null && script.StackLevel != null && !GlobalNameExists(name)) { script.StackLevel.Variables[name] = function; var handle = OnVariableChange; if (handle != null) { handle.Invoke(function.Name, function.Value, false); } } if (!globalOnly && s_locals.Count > StackLevelDelta && (localIfPossible || LocalNameExists(name) || !GlobalNameExists(name))) { AddLocalVariable(function); } else { AddGlobal(name, function, false /* not native */); } }