Esempio n. 1
0
        private LanguageAST.JsonIdentifierExpression AddJsonVariables(LanguageAST.JsonIdentifierExpression currentVar, string parentName)
        {
            if (currentVar != null)
            {
                var namedExpression = currentVar as LanguageAST.JsonIdentifierExpression.NameExpression;
                if (namedExpression != null)
                {
                    var name       = namedExpression.Item.Name;
                    var objectName = parentName == null ? name : parentName + "." + name;
                    if (!objectName.Contains("@"))
                    {
                        objectName = "@" + objectName;
                    }
                    PatriciaTrieJsonObjects.Add(DataListUtil.AddBracketsToValueIfNotExist(objectName), DataListUtil.AddBracketsToValueIfNotExist(objectName));
                    return(null);
                }

                var indexNestedExpression = currentVar as LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression;
                if (indexNestedExpression != null)
                {
                    var name       = Equals(indexNestedExpression.Item.Index, LanguageAST.Index.Star) ? indexNestedExpression.Item.ObjectName + "(*)" : indexNestedExpression.Item.ObjectName + "()";
                    var objectName = parentName == null ? name : parentName + "." + name;
                    if (!objectName.Contains("@"))
                    {
                        objectName = "@" + objectName;
                    }
                    PatriciaTrieJsonObjects.Add(DataListUtil.AddBracketsToValueIfNotExist(objectName), DataListUtil.AddBracketsToValueIfNotExist(objectName));
                    return(AddJsonVariables(indexNestedExpression.Item.Next, objectName));
                }

                var nestedNameExpression = currentVar as LanguageAST.JsonIdentifierExpression.NestedNameExpression;
                if (nestedNameExpression != null)
                {
                    var objectName = parentName == null ? nestedNameExpression.Item.ObjectName : parentName + "." + nestedNameExpression.Item.ObjectName;
                    if (!objectName.Contains("@"))
                    {
                        objectName = "@" + objectName;
                    }
                    PatriciaTrieJsonObjects.Add(DataListUtil.AddBracketsToValueIfNotExist(objectName), DataListUtil.AddBracketsToValueIfNotExist(objectName));
                    var next = nestedNameExpression.Item.Next;
                    return(AddJsonVariables(next, objectName));
                }
            }
            return(null);
        }
Esempio n. 2
0
        public void Build(LanguageAST.JsonIdentifierExpression var, string exp, JContainer container)
        {
            var jsonIdentifierExpression = var;

            if (jsonIdentifierExpression is null)
            {
                return;
            }

            if (jsonIdentifierExpression is LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression nameExpression)
            {
                BuildFromIndexNestedNameExpression(exp, container, nameExpression);
            }
            else
            {
                if (jsonIdentifierExpression is LanguageAST.JsonIdentifierExpression.NestedNameExpression nestedNameExpression)
                {
                    BuildFromNestedNameExpression(exp, container, nestedNameExpression);
                }
            }
            return;
        }
Esempio n. 3
0
        void BuildIndexMap(LanguageAST.JsonIdentifierExpression var, string exp, List <string> indexMap, JContainer container)
        {
            var jsonIdentifierExpression = var;

            if (jsonIdentifierExpression == null)
            {
                return;
            }
            if (jsonIdentifierExpression is LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression nameExpression)
            {
                var        objectName = nameExpression.Item.ObjectName;
                JContainer obj;
                JArray     arr = null;
                if (container == null)
                {
                    obj = _env.JsonObjects[objectName];
                    arr = obj as JArray;
                }
                else
                {
                    var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                    if (props != null)
                    {
                        obj = props.First as JContainer;
                        arr = obj as JArray;
                    }
                    else
                    {
                        obj = container;
                    }
                }

                if (arr != null)
                {
                    BuildIndexMapHelper(exp, indexMap, nameExpression, objectName, arr);
                }
                else
                {
                    if (!nameExpression.Item.Next.IsTerminal)
                    {
                        BuildIndexMap(nameExpression.Item.Next, exp, indexMap, obj);
                    }
                }
            }
            else
            {
                if (jsonIdentifierExpression is LanguageAST.JsonIdentifierExpression.NestedNameExpression nestedNameExpression)
                {
                    JContainer obj;
                    var        objectName = nestedNameExpression.Item.ObjectName;
                    if (container == null)
                    {
                        obj = _env.JsonObjects[objectName];
                    }
                    else
                    {
                        var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                        obj = props != null ? props.First as JContainer : container;
                    }
                    BuildIndexMap(nestedNameExpression.Item.Next, exp, indexMap, obj);
                }
            }
        }
Esempio n. 4
0
 public IList <string> Build(LanguageAST.JsonIdentifierExpression var, string exp)
 {
     Build(var, exp, null);
     return(_indexMap);
 }
        private void BuildIndexMap(LanguageAST.JsonIdentifierExpression var, string exp, List <string> indexMap, JContainer container)
        {
            var jsonIdentifierExpression = var;

            if (jsonIdentifierExpression != null)
            {
                var nameExpression = jsonIdentifierExpression as LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression;
                if (nameExpression != null)
                {
                    var        objectName = nameExpression.Item.ObjectName;
                    JContainer obj;
                    JArray     arr = null;
                    if (container == null)
                    {
                        obj = _env.JsonObjects[objectName];
                        arr = obj as JArray;
                    }
                    else
                    {
                        var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                        if (props != null)
                        {
                            obj = props.First as JContainer;
                            arr = obj as JArray;
                        }
                        else
                        {
                            obj = container;
                        }
                    }

                    if (arr != null)
                    {
                        var indexToInt = AssignEvaluation.indexToInt(LanguageAST.Index.Star, arr).ToList();
                        foreach (var i in indexToInt)
                        {
                            if (!string.IsNullOrEmpty(exp))
                            {
                                var indexed    = objectName + @"(" + i + @")";
                                var updatedExp = exp.Replace(objectName + @"(*)", indexed);
                                indexMap.Add(updatedExp);
                                BuildIndexMap(nameExpression.Item.Next, updatedExp, indexMap, arr[i - 1] as JContainer);
                            }
                        }
                    }
                    else
                    {
                        if (!nameExpression.Item.Next.IsTerminal)
                        {
                            BuildIndexMap(nameExpression.Item.Next, exp, indexMap, obj);
                        }
                    }
                }
                else
                {
                    var nestedNameExpression = jsonIdentifierExpression as LanguageAST.JsonIdentifierExpression.NestedNameExpression;
                    if (nestedNameExpression != null)
                    {
                        JContainer obj;
                        var        objectName = nestedNameExpression.Item.ObjectName;
                        if (container == null)
                        {
                            obj = _env.JsonObjects[objectName];
                        }
                        else
                        {
                            var props = container.FirstOrDefault(token => token.Type == JTokenType.Property && ((JProperty)token).Name == objectName);
                            if (props != null)
                            {
                                obj = props.First as JContainer;
                            }
                            else
                            {
                                obj = container;
                            }
                        }
                        BuildIndexMap(nestedNameExpression.Item.Next, exp, indexMap, obj);
                    }
                }
            }
        }