public static void ExprCollectAddSubNodes( ExprNode parentNode, ITree node, IDictionary<ITree, ExprNode> astExprNodeMap) { if (parentNode == null) { throw ASTWalkException.From("Invalid null expression node for '" + ASTUtil.PrintNode(node) + "'"); } if (node == null) { return; } ExprAction action = (exprNode, astExprNodeMapX, nodeX) => { astExprNodeMapX.Remove(nodeX); parentNode.AddChildNode(exprNode); }; for (int i = 0; i < node.ChildCount; i++) { ITree childNode = node.GetChild(i); RecursiveFindRemoveChildExprNode(childNode, astExprNodeMap, action); } }
public static void AddOptionalSimpleProperty(ExprNode exprNode, IToken token, VariableService variableService, StatementSpecRaw spec) { if (token == null) { return; } var node = ASTExprHelper.ResolvePropertyOrVariableIdentifier(token.Text, variableService, spec); exprNode.AddChildNode(node); }
public static void AddOptionalNumber(ExprNode exprNode, EsperEPL2GrammarParser.NumberContext number) { if (number == null) { return; } ExprConstantNode constantNode = new ExprConstantNodeImpl(ASTConstantHelper.Parse(number)); exprNode.AddChildNode(constantNode); }
private static Pair <ExprNode, ExprTableAccessNode> HandleTableSubchain( IList <ExprNode> tableKeys, IList <Chainable> chain, TableMetaData table, Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction) { if (chain.IsEmpty()) { var nodeX = new ExprTableAccessNodeTopLevel(table.TableName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } // We make an exception when the table is keyed and the column is found and there are no table keys provided. // This accommodates the case "select MyTable.a from MyTable". var columnOrOtherName = chain[0].GetRootNameOrEmptyString(); var tableColumn = table.Columns.Get(columnOrOtherName); if (tableColumn != null && table.IsKeyed && tableKeys.IsEmpty()) { return(null); // let this be resolved as an identifier } if (chain.Count == 1) { if (chain[0] is ChainableName) { var nodeX = new ExprTableAccessNodeSubprop(table.TableName, columnOrOtherName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } if (columnOrOtherName.Equals("keys", StringComparison.InvariantCultureIgnoreCase)) { var nodeX = new ExprTableAccessNodeKeys(table.TableName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } else { throw new ValidationException( "Invalid use of table '" + table.TableName + "', unrecognized use of function '" + columnOrOtherName + "', expected 'keys()'"); } } var node = new ExprTableAccessNodeSubprop(table.TableName, columnOrOtherName); node.AddChildNodes(tableKeys); var subchain = chain.SubList(1, chain.Count); ExprNode exprNode = dotNodeFunction.Invoke(subchain); exprNode.AddChildNode(node); return(new Pair <ExprNode, ExprTableAccessNode>(exprNode, node)); }
public static void ExprCollectAddSubNodesExpressionCtx(ExprNode parentNode, IList <EsperEPL2GrammarParser.ExpressionContext> expressionContexts, IDictionary <ITree, ExprNode> astExprNodeMap) { ExprAction action = (exprNode, astExprNodeMapX, node) => { astExprNodeMapX.Remove(node); parentNode.AddChildNode(exprNode); }; foreach (var ctx in expressionContexts) { RecursiveFindRemoveChildExprNode(ctx, astExprNodeMap, action); } }
private static ExprNode HandleDeclaredExpr( ExprDeclaredNodeImpl node, IList <Chainable> chain, Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction) { if (chain.Count == 1) { return(node); } IList <Chainable> spec = new List <Chainable>(chain.SubList(1, chain.Count)); ExprNode dot = dotNodeFunction.Invoke(spec); dot.AddChildNode(node); return(dot); }
public static void ExprCollectAddSingle(ExprNode parentNode, ITree node, IDictionary <ITree, ExprNode> astExprNodeMap) { if (parentNode == null) { throw ASTWalkException.From("Invalid null expression node for '" + ASTUtil.PrintNode(node) + "'"); } if (node == null) { return; } ExprAction action = (exprNodeX, astExprNodeMapX, nodeX) => { astExprNodeMapX.Remove(nodeX); parentNode.AddChildNode(exprNodeX); }; RecursiveFindRemoveChildExprNode(node, astExprNodeMap, action); }
private static ExprNode HandleSingleRowExt( ExprNode singleRowExtNode, IList <Chainable> chain, Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction) { singleRowExtNode.AddChildNodes(chain[0].GetParametersOrEmpty()); if (chain.Count == 1) { return(singleRowExtNode); } IList <Chainable> spec = new List <Chainable>(chain.SubList(1, chain.Count)); ExprNode dot = dotNodeFunction.Invoke(spec); dot.AddChildNode(singleRowExtNode); return(dot); }
private static ExprNode HandleMinMax( string chainFirstLowerCase, IList <Chainable> chain, Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction) { var node = HandleMinMaxNode(chainFirstLowerCase, chain[0]); if (chain.Count == 1) { return(node); } IList <Chainable> spec = new List <Chainable>(chain.SubList(1, chain.Count)); ExprNode dot = dotNodeFunction.Invoke(spec); dot.AddChildNode(node); return(dot); }