示例#1
0
        /// <summary>
        /// Resolve "table" and "table.property" when nested-property, not chainable
        /// </summary>
        public static ExprTableAccessNode CheckTableNameGetExprForProperty(TableService tableService, string propertyName)
        {
            // handle "var_name" alone, without chained, like an simple event property
            var index = ASTUtil.UnescapedIndexOfDot(propertyName);

            if (index == -1)
            {
                if (tableService.GetTableMetadata(propertyName) != null)
                {
                    return(new ExprTableAccessNodeTopLevel(propertyName));
                }
                return(null);
            }

            // handle "var_name.column", without chained, like a nested event property
            var tableName = ASTUtil.UnescapeDot(propertyName.Substring(0, index));

            if (tableService.GetTableMetadata(tableName) == null)
            {
                return(null);
            }

            // it is a tables's subproperty
            var sub = propertyName.Substring(index + 1);

            return(new ExprTableAccessNodeSubprop(tableName, sub));
        }
示例#2
0
        public void TestUnescapeIndexOf()
        {
            Object [][] inout = new Object[][] {
                new Object[] { "a", -1 },
                new Object[] { "", -1 },
                new Object[] { " ", -1 },
                new Object[] { ".", 0 },
                new Object[] { " . .", 1 },
                new Object[] { "a.", 1 },
                new Object[] { ".a", 0 },
                new Object[] { "a.b", 1 },
                new Object[] { "a..b", 1 },
                new Object[] { "a\\.b", -1 },
                new Object[] { "a.\\..b", 1 },
                new Object[] { "a\\..b", 3 },
                new Object[] { "a.b.c", 1 },
                new Object[] { "abc.", 3 }
            };

            for (int i = 0; i < inout.Length; i++)
            {
                var @in      = (String)inout[i][0];
                var expected = (int?)inout[i][1];
                Assert.AreEqual(expected, ASTUtil.UnescapedIndexOfDot(@in), "for input " + @in);
            }
        }
示例#3
0
        /// <summary>
        /// Resolve "table.property", not chainable
        /// </summary>
        public static Pair <ExprTableAccessNode, ExprDotNode> CheckTableNameGetExprForSubproperty(TableService tableService, string tableName, string subproperty)
        {
            var metadata = tableService.GetTableMetadata(tableName);

            if (metadata == null)
            {
                return(null);
            }

            var index = ASTUtil.UnescapedIndexOfDot(subproperty);

            if (index == -1)
            {
                if (metadata.KeyTypes.Length > 0)
                {
                    return(null);
                }
                var tableNodeX = new ExprTableAccessNodeSubprop(tableName, subproperty);
                return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNodeX, null));
            }

            // we have a nested subproperty such as "tablename.subproperty.abc"
            IList <ExprChainedSpec> chainedSpecs = new List <ExprChainedSpec>(1);

            chainedSpecs.Add(new ExprChainedSpec(subproperty.Substring(index + 1), Collections.GetEmptyList <ExprNode>(), true));
            var tableNode = new ExprTableAccessNodeSubprop(tableName, subproperty.Substring(0, index));
            var dotNode   = new ExprDotNode(chainedSpecs, false, false);

            dotNode.AddChildNode(tableNode);
            return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNode, dotNode));
        }
示例#4
0
        public static Pair <ExprTableAccessNode, IList <ExprChainedSpec> > CheckTableNameGetLibFunc(
            TableService tableService,
            EngineImportService engineImportService,
            LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory> plugInAggregations,
            string engineURI,
            string classIdent,
            IList <ExprChainedSpec> chain)
        {
            var index = ASTUtil.UnescapedIndexOfDot(classIdent);

            // handle special case "table.Keys()" function
            if (index == -1)
            {
                if (tableService.GetTableMetadata(classIdent) == null)
                {
                    return(null); // not a table
                }
                var funcName = chain[1].Name;
                if (funcName.ToLowerInvariant().Equals("keys"))
                {
                    var subchain = chain.SubList(2, chain.Count);
                    var node     = new ExprTableAccessNodeKeys(classIdent);
                    return(new Pair <ExprTableAccessNode, IList <ExprChainedSpec> >(node, subchain));
                }
                else
                {
                    throw ASTWalkException.From(
                              "Invalid use of variable '" + classIdent + "', unrecognized use of function '" + funcName +
                              "', expected 'keys()'");
                }
            }

            // Handle "table.property" (without the variable[...] syntax since this is ungrouped use)
            var tableName = ASTUtil.UnescapeDot(classIdent.Substring(0, index));

            if (tableService.GetTableMetadata(tableName) == null)
            {
                return(null);
            }

            // this is a table access expression
            var sub = classIdent.Substring(index + 1);

            return(HandleTable(engineImportService, plugInAggregations, engineURI, tableName, sub, chain));
        }