Example #1
0
        public static Variable ExtractArrayElement(Variable array,
                                                   List <Variable> indices)
        {
            Variable currLevel = array;

            for (int i = 0; i < indices.Count; i++)
            {
                Variable index      = indices [i];
                int      arrayIndex = currLevel.GetArrayIndex(index);

                int tupleSize = currLevel.Tuple != null ? currLevel.Tuple.Count : 0;
                if (arrayIndex < 0 || arrayIndex >= tupleSize)
                {
                    throw new ArgumentException("Unknown index [" + index.AsString() +
                                                "] for tuple of size " + tupleSize);
                }
                currLevel = currLevel.Tuple [arrayIndex];
            }
            return(currLevel);
        }
Example #2
0
        public static Variable ExtractArrayElement(Variable array,
                                                   List <Variable> indices,
                                                   ParsingScript script)
        {
            Variable currLevel = array;

            for (int i = 0; i < indices.Count; i++)
            {
                Variable index      = indices[i];
                int      arrayIndex = currLevel.GetArrayIndex(index);

                int tupleSize = currLevel.Tuple != null ? currLevel.Tuple.Count : 0;
                if (arrayIndex < 0 || arrayIndex >= tupleSize)
                {
                    ThrowErrorMsg("Unknown index [" + index.AsString() +
                                  "] for tuple of size " + tupleSize, script, index.AsString());
                }
                currLevel = currLevel.Tuple[arrayIndex];
            }
            return(currLevel);
        }
Example #3
0
        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);
        }