public static IList <ColumnDesc> GetColTypeList(EsperEPL2GrammarParser.CreateColumnListContext ctx) { if (ctx == null) { return(Collections.GetEmptyList <ColumnDesc>()); } IList <ColumnDesc> result = new List <ColumnDesc>(ctx.createColumnListElement().Length); foreach (var colctx in ctx.createColumnListElement()) { IList <EsperEPL2GrammarParser.ClassIdentifierContext> idents = colctx.classIdentifier(); var name = ASTUtil.UnescapeClassIdent(idents[0]); string type; if (colctx.VALUE_NULL() != null) { type = null; } else { type = ASTUtil.UnescapeClassIdent(idents[1]); } var array = colctx.b != null; var primitiveArray = ValidateIsPrimitiveArray(colctx.p); result.Add(new ColumnDesc(name, type, array, primitiveArray)); } return(result); }
public static FilterSpecRaw WalkFilterSpec(EsperEPL2GrammarParser.EventFilterExpressionContext ctx, PropertyEvalSpec propertyEvalSpec, IDictionary <ITree, ExprNode> astExprNodeMap) { var eventName = ASTUtil.UnescapeClassIdent(ctx.classIdentifier()); var exprNodes = ctx.expressionList() != null?ASTExprHelper.ExprCollectSubNodes(ctx.expressionList(), 0, astExprNodeMap) : new List <ExprNode>(1); return(new FilterSpecRaw(eventName, exprNodes, propertyEvalSpec)); }
private static String[] ParseParamsStreamNames(EsperEPL2GrammarParser.GopParamsItemContext item) { IList <String> paramNames = new List <String>(1); if (item.gopParamsItemMany() != null) { foreach (var ctx in item.gopParamsItemMany().classIdentifier()) { paramNames.Add(ctx.GetText()); } } else { paramNames.Add(ASTUtil.UnescapeClassIdent(item.classIdentifier())); } return(paramNames.ToArray()); }
/// <summary> /// Walk an annotation root name or child node (nested annotations). /// </summary> /// <param name="ctx">annotation walk node</param> /// <param name="engineImportService">for engine imports</param> /// <returns>annotation descriptor</returns> /// <throws>ASTWalkException if the walk failed</throws> public static AnnotationDesc Walk(EsperEPL2GrammarParser.AnnotationEnumContext ctx, EngineImportService engineImportService) { var name = ASTUtil.UnescapeClassIdent(ctx.classIdentifier()); IList <Pair <String, Object> > values = new List <Pair <String, Object> >(); if (ctx.elementValueEnum() != null) { var value = WalkValue(ctx.elementValueEnum(), engineImportService); values.Add(new Pair <String, Object>("Value", value)); } else if (ctx.elementValuePairsEnum() != null) { WalkValuePairs(ctx.elementValuePairsEnum(), values, engineImportService); } return(new AnnotationDesc(name, values)); }
private static GraphOperatorOutputItemType ParseType(EsperEPL2GrammarParser.GopOutTypeParamContext ctx) { if (ctx.q != null) { return(new GraphOperatorOutputItemType(true, null, null)); } var className = ASTUtil.UnescapeClassIdent(ctx.gopOutTypeItem().classIdentifier()); IList <GraphOperatorOutputItemType> typeParams = new List <GraphOperatorOutputItemType>(); if (ctx.gopOutTypeItem().gopOutTypeList() != null) { IList <EsperEPL2GrammarParser.GopOutTypeParamContext> pctxs = ctx.gopOutTypeItem().gopOutTypeList().gopOutTypeParam(); foreach (var pctx in pctxs) { var type = ParseType(pctx); typeParams.Add(type); } } return(new GraphOperatorOutputItemType(false, className, typeParams)); }
private static ASTLibModel GetModel(EsperEPL2GrammarParser.LibFunctionContext ctx, CommonTokenStream tokenStream) { var root = ctx.libFunctionWithClass(); IList <EsperEPL2GrammarParser.LibFunctionNoClassContext> ctxElements = ctx.libFunctionNoClass(); // there are no additional methods if (ctxElements == null || ctxElements.IsEmpty()) { var classIdent = root.classIdentifier() == null ? null : ASTUtil.UnescapeClassIdent(root.classIdentifier()); var ele = FromRoot(root); return(new ASTLibModel(classIdent, Collections.SingletonList(ele))); } // add root and chain to just a list of elements IList <ASTLibModelChainElement> chainElements = new List <ASTLibModelChainElement>(ctxElements.Count + 1); var rootElement = FromRoot(root); chainElements.Add(rootElement); foreach (var chainedCtx in ctxElements) { var chainedElement = new ASTLibModelChainElement(chainedCtx.funcIdentChained().GetText(), chainedCtx.libFunctionArgs(), chainedCtx.l != null); chainElements.Add(chainedElement); } // determine/remove the list of chain elements, from the start and uninterrupted, that don't have parameters (no parenthesis 'l') IList <ASTLibModelChainElement> chainElementsNoArgs = new List <ASTLibModelChainElement>(chainElements.Count); for (int ii = 0; ii < chainElements.Count; ii++) { var element = chainElements[ii]; if (!element.HasLeftParen) { // has no parenthesis, therefore part of class identifier chainElementsNoArgs.Add(element); chainElements.RemoveAt(ii--); } else { // else stop here break; } } // write the class identifier including the no-arg chain elements var classIdentBuf = new StringBuilder(); var delimiter = ""; if (root.classIdentifier() != null) { classIdentBuf.Append(ASTUtil.UnescapeClassIdent(root.classIdentifier())); delimiter = "."; } foreach (var noarg in chainElementsNoArgs) { classIdentBuf.Append(delimiter); classIdentBuf.Append(noarg.FuncName); delimiter = "."; } if (chainElements.IsEmpty()) { // would this be an event property, but then that is handled greedily by parser throw ASTWalkException.From("Encountered unrecognized lib function call", tokenStream, ctx); } // class ident can be null if empty var classIdentifierString = classIdentBuf.ToString(); var classIdentifier = classIdentifierString.Length > 0 ? classIdentifierString : null; return(new ASTLibModel(classIdentifier, chainElements)); }
public static Pair <ExpressionDeclItem, ExpressionScriptProvided> WalkExpressionDecl( EsperEPL2GrammarParser.ExpressionDeclContext ctx, IList <String> scriptBodies, IDictionary <ITree, ExprNode> astExprNodeMap, CommonTokenStream tokenStream) { var name = ctx.name.Text; if (ctx.alias != null) { if (ctx.alias.Text.ToLower().Trim() != "alias") { throw ASTWalkException.From("For expression alias '" + name + "' expecting 'alias' keyword but received '" + ctx.alias.Text + "'"); } if (ctx.columnList() != null) { throw ASTWalkException.From("For expression alias '" + name + "' expecting no parameters but received '" + tokenStream.GetText(ctx.columnList()) + "'"); } if (ctx.expressionDef() != null && ctx.expressionDef().expressionLambdaDecl() != null) { throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression without parameters but received '" + tokenStream.GetText(ctx.expressionDef().expressionLambdaDecl()) + "'"); } if (ctx.expressionDef().stringconstant() != null) { throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression but received a script"); } var exprNode = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0]; var alias = ctx.name.Text; var decl = new ExpressionDeclItem(alias, Collections.GetEmptyList <String>(), exprNode, true); return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(decl, null)); } if (ctx.expressionDef().stringconstant() != null) { var expressionText = scriptBodies[0]; scriptBodies.RemoveAt(0); var parameters = ASTUtil.GetIdentList(ctx.columnList()); var optionalReturnType = ctx.classIdentifier() == null ? null : ASTUtil.UnescapeClassIdent(ctx.classIdentifier()); var optionalReturnTypeArray = ctx.array != null; var optionalDialect = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.Text; var script = new ExpressionScriptProvided( name, expressionText, parameters, optionalReturnType, optionalReturnTypeArray, optionalDialect); return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(null, script)); } var ctxexpr = ctx.expressionDef(); var inner = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0]; var parametersNames = Collections.GetEmptyList <string>(); var lambdactx = ctxexpr.expressionLambdaDecl(); if (ctxexpr.expressionLambdaDecl() != null) { parametersNames = ASTLibFunctionHelper.GetLambdaGoesParams(lambdactx); } var expr = new ExpressionDeclItem(name, parametersNames, inner, false); return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(expr, null)); }
private static CreateTableColumn GetColumn(EsperEPL2GrammarParser.CreateTableColumnContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, EngineImportService engineImportService) { string columnName = ctx.n.Text; ExprNode optExpression = null; if (ctx.builtinFunc() != null || ctx.libFunction() != null) { optExpression = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0]; } string optTypeName = null; bool? optTypeIsArray = null; bool? optTypeIsPrimitiveArray = null; if (ctx.createTableColumnPlain() != null) { EsperEPL2GrammarParser.CreateTableColumnPlainContext sub = ctx.createTableColumnPlain(); optTypeName = ASTUtil.UnescapeClassIdent(sub.classIdentifier()); optTypeIsArray = sub.b != null; optTypeIsPrimitiveArray = ASTCreateSchemaHelper.ValidateIsPrimitiveArray(sub.p); } bool primaryKey = false; if (ctx.p != null) { if (ctx.p.Text.ToLower() != "primary") { throw ASTWalkException.From("Invalid keyword '" + ctx.p.Text + "' encountered, expected 'primary key'"); } if (ctx.k.Text.ToLower() != "key") { throw ASTWalkException.From("Invalid keyword '" + ctx.k.Text + "' encountered, expected 'primary key'"); } primaryKey = true; } IList <AnnotationDesc> annots = Collections.GetEmptyList <AnnotationDesc>(); if (ctx.annotationEnum() != null) { annots = new List <AnnotationDesc>(ctx.annotationEnum().Length); foreach (EsperEPL2GrammarParser.AnnotationEnumContext anctx in ctx.annotationEnum()) { annots.Add(ASTAnnotationHelper.Walk(anctx, engineImportService)); } } if (ctx.propertyExpressionAnnotation() != null) { if (annots.IsEmpty()) { annots = new List <AnnotationDesc>(); } foreach (EsperEPL2GrammarParser.PropertyExpressionAnnotationContext anno in ctx.propertyExpressionAnnotation()) { annots.Add(new AnnotationDesc(anno.n.Text, anno.v.Text)); } } return(new CreateTableColumn(columnName, optExpression, optTypeName, optTypeIsArray, optTypeIsPrimitiveArray, annots, primaryKey)); }