Beispiel #1
0
 static void ParseJObjectIntoVariable(JObject jsonObject, Variable aVariable)
 {
     foreach (var currentToken in jsonObject)
     {
         Variable currentVariable = GetVariableForJToken(currentToken.Value);
         aVariable.SetHashVariable(currentToken.Key, currentVariable);
     }
 }
Beispiel #2
0
        public static Variable CreateVariableFromJsonString(string aJSONString)
        {
            Variable newValue = new Variable(Variable.VarType.ARRAY);

            try
            {
                JObject jsonObject = JObject.Parse(aJSONString);
                ParseJObjectIntoVariable(jsonObject, newValue);
            }
            catch (Exception e)
            {
                newValue.SetHashVariable("error", new Variable(true));
                newValue.SetHashVariable("message", new Variable(e.Message));
            }

            return(newValue);
        }
Beispiel #3
0
        static void MergeStrings(Variable leftCell, Variable rightCell, ParsingScript script)
        {
            switch (leftCell.Action)
            {
            case "+":
                leftCell.String = leftCell.AsString() + rightCell.AsString();
                break;

            case "<":
                string arg1 = leftCell.AsString();
                string arg2 = rightCell.AsString();
                leftCell.Value = Convert.ToDouble(string.Compare(arg1, arg2) < 0);
                break;

            case ">":
                leftCell.Value = Convert.ToDouble(
                    string.Compare(leftCell.AsString(), rightCell.AsString()) > 0);
                break;

            case "<=":
                leftCell.Value = Convert.ToDouble(
                    string.Compare(leftCell.AsString(), rightCell.AsString()) <= 0);
                break;

            case ">=":
                leftCell.Value = Convert.ToDouble(
                    string.Compare(leftCell.AsString(), rightCell.AsString()) >= 0);
                break;

            case "==":
                leftCell.Value = Convert.ToDouble(
                    string.Compare(leftCell.AsString(), rightCell.AsString()) == 0);
                break;

            case "!=":
                leftCell.Value = Convert.ToDouble(
                    string.Compare(leftCell.AsString(), rightCell.AsString()) != 0);
                break;

            case ":":
                leftCell.SetHashVariable(leftCell.AsString(), rightCell);
                break;

            case ")":
                break;

            default:
                Utils.ThrowErrorMsg("Can't process operation [" + leftCell.Action + "] on strings.",
                                    script, leftCell.Action);
                break;
            }
        }
Beispiel #4
0
        static Variable ExtractObject(ParsingScript script)
        {
            Variable newValue = new Variable(Variable.VarType.ARRAY);

            while (script.StillValid() && (newValue.Count == 0 || script.Current == ','))
            {
                script.Forward();
                string key = Utils.GetToken(script, SEP);
                script.MoveForwardIf(':');

                Variable valueVar = ExtractValue(script);
                newValue.SetHashVariable(key, valueVar);
            }
            script.MoveForwardIf('}');

            return(newValue);
        }
        private static int ExtendArrayHelper(Variable parent, Variable indexVar)
        {
            parent.SetAsArray();

            int arrayIndex = parent.GetArrayIndex(indexVar);

            if (arrayIndex < 0)
            {
                // This is not a "normal index" but a new string for the dictionary.
                string hash = indexVar.AsString();
                arrayIndex = parent.SetHashVariable(hash, Variable.NewEmpty());
                return(arrayIndex);
            }

            if (parent.Tuple.Count <= arrayIndex)
            {
                for (int i = parent.Tuple.Count; i <= arrayIndex; i++)
                {
                    parent.Tuple.Add(Variable.NewEmpty());
                }
            }
            return(arrayIndex);
        }