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; } if (!globalOnly && s_locals.Count > StackLevelDelta && (localIfPossible || LocalNameExists(name) || !GlobalNameExists(name))) { AddLocalVariable(function); } else { AddGlobal(name, function, false /* not native */); } }
static ParserFunction GetRegisteredAction(string name, ParsingScript script, ref string action) { if (Constants.CheckReserved(name)) { return(null); } if (ActionForUndefined(action) && script.Rest.StartsWith(Constants.UNDEFINED)) { IsUndefinedFunction undef = new IsUndefinedFunction(name, action); return(undef); } ActionFunction actionFunction = GetAction(action); // If passed action exists and is registered we are done. if (actionFunction == null) { return(null); } ActionFunction theAction = actionFunction.NewInstance() as ActionFunction; theAction.Name = name; theAction.Action = action; action = null; return(theAction); }
public static void AddGlobalOrLocalVariable(string name, GetVarFunction function, ParsingScript script = null) { name = Constants.ConvertName(name); if (Constants.CheckReserved(name)) { Utils.ThrowErrorMsg(name + " is a reserved name.", script, name); } Dictionary <string, ParserFunction> lastLevel = GetLastLevel(); if (lastLevel != null && s_lastExecutionLevel.IsNamespace && !string.IsNullOrWhiteSpace(s_namespace)) { name = s_namespacePrefix + name; } function.Name = Constants.GetRealName(name); function.Value.ParamName = function.Name; if (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); } } else if (s_locals.Count > StackLevelDelta && (LocalNameExists(name) || !GlobalNameExists(name))) { AddLocalVariable(function); } else { AddGlobal(name, function, false /* not native */); } }
public static bool CheckLegalName(string name, ParsingScript script = null, bool throwError = true) { if (string.IsNullOrWhiteSpace(name) || Constants.CheckReserved(name)) { if (!throwError) { return(false); } Utils.ThrowErrorMsg(name + " is a reserved name.", script, name); } if (Char.IsDigit(name[0]) || name[0] == '-') { if (!throwError) { return(false); } Utils.ThrowErrorMsg(name + " has illegal first character " + name[0], null, name); } return(true); }