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)); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 2, m_name, true); string varName = args[0].AsString(); // 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 = args[1]; bool removed = currentValue.Tuple.Remove(item); ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(currentValue)); return(new Variable(removed)); }
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, 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); }
public static Object GetVariableValue(string name, ParsingScript script) { var field = typeof(Statics).GetField(name); Utils.CheckNotNull(field, name, script); Object result = field.GetValue(null); return(result); }
public static Variable GetVariable(string varName, ParsingScript script) { ParserFunction func = ParserFunction.GetFunction(varName); Utils.CheckNotNull(varName, func); Variable varValue = func.GetValue(script); return(varValue); }
protected override Variable Evaluate(ParsingScript script) { Variable varName = Utils.GetItem(script); Utils.CheckNotNull(varName, m_name); List <Variable> results = varName.GetAllKeys(); return(new Variable(results)); }
public static bool SetVariableValue(string name, Object value, ParsingScript script) { Type type = typeof(Statics); var props = type.GetProperties(); var members = type.GetMembers(); var methods = type.GetMethods(); var fields = type.GetFields(); var field = type.GetField(name); Utils.CheckNotNull(field, name, script); field.SetValue(null, Convert.ChangeType(value, field.FieldType)); return(true); }
protected override Variable Evaluate(ParsingScript script) { string funcName = Utils.GetToken(script, Constants.TOKEN_SEPARATION); ParserFunction function = ParserFunction.GetFunction(funcName); CustomFunction custFunc = function as CustomFunction; Utils.CheckNotNull(funcName, custFunc); string body = Utils.BeautifyScript(custFunc.Body, custFunc.Header); Translation.PrintScript(body); return(new Variable(body)); }
protected override Variable Evaluate(ParsingScript script) { bool prefix = string.IsNullOrWhiteSpace(m_name); if (prefix)// If it is a prefix we do not have the variable name yet. { m_name = Utils.GetToken(script, Constants.TOKEN_SEPARATION); } // Value to be added to the variable: int valueDelta = m_action == Constants.INCREMENT ? 1 : -1; int returnDelta = prefix ? valueDelta : 0; // Check if the variable to be set has the form of x[a][b], // meaning that this is an array element. double newValue = 0; List <Variable> arrayIndices = Utils.GetArrayIndices(ref m_name); ParserFunction func = ParserFunction.GetFunction(m_name); Utils.CheckNotNull(m_name, func); Variable currentValue = func.GetValue(script); if (arrayIndices.Count > 0 || script.TryCurrent() == Constants.START_ARRAY) { if (prefix) { string tmpName = m_name + script.Rest; int delta = 0; arrayIndices = Utils.GetArrayIndices(ref tmpName, ref delta); script.Forward(Math.Max(0, delta - tmpName.Length)); } Variable element = Utils.ExtractArrayElement(currentValue, arrayIndices); script.MoveForwardIf(Constants.END_ARRAY); newValue = element.Value + returnDelta; element.Value += valueDelta; } else // A normal variable. { newValue = currentValue.Value + returnDelta; currentValue.Value += valueDelta; } ParserFunction.AddGlobalOrLocalVariable(m_name, new GetVarFunction(currentValue)); return(new Variable(newValue)); }
public Variable SetProperty(string propName, Variable value, ParsingScript script, string baseName = "") { int ind = propName.IndexOf('.'); if (ind > 0) { // The case a.b.c = ... is dealt here recursively string varName = propName.Substring(0, ind); string actualPropName = propName.Substring(ind + 1); Variable property = GetProperty(varName); Utils.CheckNotNull(property, varName, script); return(property.SetProperty(actualPropName, value, script, baseName)); } return(FinishSetProperty(propName, value, baseName)); }
public static Variable GetVariable(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 = func.GetValue(script); Utils.CheckNotNull(varValue, varName, script); return(varValue); }
public static async Task <Variable> GetVariableAsync(string varName, ParsingScript script, bool testNull = true) { ParserFunction func = ParserFunction.GetFunction(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); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string funcName = args[0].AsString(); ParserFunction function = ParserFunction.GetFunction(funcName); CustomFunction custFunc = function as CustomFunction; Utils.CheckNotNull(funcName, custFunc); string body = Utils.BeautifyScript(custFunc.Body, custFunc.Header); Translation.PrintScript(body); return(new Variable(body)); }
protected override Variable Evaluate(ParsingScript script) { // Value to be added to the variable: Variable right = Utils.GetItem(script); List <Variable> arrayIndices = Utils.GetArrayIndices(ref m_name); ParserFunction func = ParserFunction.GetFunction(m_name); Utils.CheckNotNull(m_name, func); Variable currentValue = func.GetValue(script); Variable left = currentValue; if (arrayIndices.Count > 0)// array element { left = Utils.ExtractArrayElement(currentValue, arrayIndices); script.MoveForwardIf(Constants.END_ARRAY); } if (left.Type == Variable.VarType.NUMBER) { NumberOperator(left, right, m_action); } else { StringOperator(left, right, m_action); } if (arrayIndices.Count > 0)// array element { AssignFunction.ExtendArray(currentValue, arrayIndices, 0, left); ParserFunction.AddGlobalOrLocalVariable(m_name, new GetVarFunction(currentValue)); } else { ParserFunction.AddGlobalOrLocalVariable(m_name, new GetVarFunction(left)); } return(left); }
public static void Add(NameValueCollection langDictionary, string origName, Dictionary <string, string> translations1, Dictionary <string, string> translations2) { AddNativeKeyword(origName); string translation = langDictionary[origName]; if (string.IsNullOrWhiteSpace(translation)) { // The translation is not provided for this function. translations1[origName] = origName; translations2[origName] = origName; return; } AddNativeKeyword(translation); translations1[origName] = translation; translations2[translation] = origName; if (translation.IndexOfAny((" \t\r\n").ToCharArray()) >= 0) { throw new ArgumentException("Translation of [" + translation + "] contains white spaces"); } ParserFunction origFunction = ParserFunction.GetFunction(origName, null); Utils.CheckNotNull(origName, origFunction, null); ParserFunction.RegisterFunction(translation, origFunction); // Also add the translation to the list of functions after which there // can be a space (besides a parenthesis). if (Constants.FUNCT_WITH_SPACE.Contains(origName)) { Constants.FUNCT_WITH_SPACE.Add(translation); } if (Constants.FUNCT_WITH_SPACE_ONCE.Contains(origName)) { Constants.FUNCT_WITH_SPACE_ONCE.Add(translation); } }
public async Task <Variable> SetPropertyAsync(string propName, Variable value, string baseName = "") { Variable result = Variable.EmptyInstance; propName = Constants.ConvertName(propName); int ind = propName.IndexOf('.'); if (ind > 0) { // The case a.b.c = ... is dealt here recursively string varName = propName.Substring(0, ind); string actualPropName = propName.Substring(ind + 1); Variable property = await GetPropertyAsync(varName); Utils.CheckNotNull(property, varName); result = await property.SetPropertyAsync(actualPropName, value, baseName); return(result); } return(FinishSetProperty(propName, value, baseName)); }
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); }