private static object WalkValue( EsperEPL2GrammarParser.ElementValueEnumContext ctx, ImportServiceCompileTime importService) { if (ctx.elementValueArrayEnum() != null) { return WalkArray(ctx.elementValueArrayEnum(), importService); } if (ctx.annotationEnum() != null) { return Walk(ctx.annotationEnum(), importService); } if (ctx.v != null) { return ctx.v.Text; } if (ctx.classIdentifier() != null) { return WalkClassIdent(ctx.classIdentifier(), importService); } return ASTConstantHelper.Parse(ctx.constant()); }
private static object ParseNumOrVariableIdent( EsperEPL2GrammarParser.NumberconstantContext num, IToken ident) { if (ident != null) { return ident.Text; } return ASTConstantHelper.Parse(num); }
public static void AddOptionalNumber( ExprNode exprNode, EsperEPL2GrammarParser.NumberContext number) { if (number == null) { return; } ExprConstantNode constantNode = new ExprConstantNodeImpl(ASTConstantHelper.Parse(number)); exprNode.AddChildNode(constantNode); }
public static object Walk( CommonTokenStream tokenStream, EsperEPL2GrammarParser.JsonvalueContext node) { if (node.constant() != null) { EsperEPL2GrammarParser.ConstantContext constCtx = node.constant(); if (constCtx.stringconstant() != null) { return ExtractString(constCtx.stringconstant().GetText()); } else { return ASTConstantHelper.Parse(constCtx.GetChild(0)); } } else if (node.jsonobject() != null) { return WalkObject(tokenStream, node.jsonobject()); } else if (node.jsonarray() != null) { return WalkArray(tokenStream, node.jsonarray()); } throw ASTWalkException.From("Encountered unexpected node type in json tree", tokenStream, node); }
private static ContextSpec WalkChoice( EsperEPL2GrammarParser.CreateContextChoiceContext ctx, IDictionary<ITree, ExprNode> astExprNodeMap, IDictionary<ITree, EvalForgeNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec) { // temporal fixed (start+end) and overlapping (initiated/terminated) if (ctx.START() != null || ctx.INITIATED() != null) { ExprNode[] distinctExpressions = null; if (ctx.createContextDistinct() != null) { if (ctx.createContextDistinct().expressionList() == null) { distinctExpressions = ExprNodeUtilityQuery.EMPTY_EXPR_ARRAY; } else { distinctExpressions = ASTExprHelper.ExprCollectSubNodesPerNode( ctx.createContextDistinct().expressionList().expression(), astExprNodeMap); } } ContextSpecCondition startEndpoint; if (ctx.START() != null) { var immediate = CheckNow(ctx.i); if (immediate) { startEndpoint = ContextSpecConditionImmediate.INSTANCE; } else { startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); } } else { var immediate = CheckNow(ctx.i); startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, immediate); } var overlapping = ctx.INITIATED() != null; var endEndpoint = GetContextCondition(ctx.r2, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); return new ContextSpecInitiatedTerminated(startEndpoint, endEndpoint, overlapping, distinctExpressions); } // partitioned if (ctx.PARTITION() != null) { IList<EsperEPL2GrammarParser.CreateContextPartitionItemContext> partitions = ctx.createContextPartitionItem(); IList<ContextSpecKeyedItem> rawSpecs = new List<ContextSpecKeyedItem>(); foreach (var partition in partitions) { var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(partition.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); propertyEvalSpec = null; IList<string> propertyNames = new List<string>(); IList<EsperEPL2GrammarParser.ChainableContext> properties = partition.chainable(); foreach (var property in properties) { var propertyName = ASTUtil.GetPropertyName(property, 0); propertyNames.Add(propertyName); } ASTExprHelper.ExprCollectSubNodes(partition, 0, astExprNodeMap); // remove expressions rawSpecs.Add( new ContextSpecKeyedItem( filterSpec, propertyNames, partition.keywordAllowedIdent() == null ? null : partition.keywordAllowedIdent().GetText())); } IList<ContextSpecConditionFilter> optionalInit = null; if (ctx.createContextPartitionInit() != null) { optionalInit = GetContextPartitionInit(ctx.createContextPartitionInit().createContextFilter(), astExprNodeMap); } ContextSpecCondition optionalTermination = null; if (ctx.createContextPartitionTerm() != null) { optionalTermination = GetContextCondition( ctx.createContextPartitionTerm().createContextRangePoint(), astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); } return new ContextSpecKeyed(rawSpecs, optionalInit, optionalTermination); } if (ctx.COALESCE() != null) { // hash IList<EsperEPL2GrammarParser.CreateContextCoalesceItemContext> coalesces = ctx.createContextCoalesceItem(); IList<ContextSpecHashItem> rawSpecs = new List<ContextSpecHashItem>(coalesces.Count); foreach (var coalesce in coalesces) { var chain = ASTChainSpecHelper.GetChainables(coalesce.chainable(), astExprNodeMap); var func = chain[0]; var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(coalesce.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); propertyEvalSpec = null; rawSpecs.Add(new ContextSpecHashItem(func, filterSpec)); } var granularity = ctx.g.Text; if (!granularity.ToLowerInvariant().Equals("granularity")) { throw ASTWalkException.From("Expected 'granularity' keyword after list of coalesce items, found '" + granularity + "' instead"); } var num = ASTConstantHelper.Parse(ctx.number()); var preallocateStr = ctx.p?.Text; if (preallocateStr != null && !preallocateStr.ToLowerInvariant().Equals("preallocate")) { throw ASTWalkException.From( "Expected 'preallocate' keyword after list of coalesce items, found '" + preallocateStr + "' instead"); } if (!num.GetType().IsNumericNonFP() || num.GetType().GetBoxedType() == typeof(long?)) { throw ASTWalkException.From("Granularity provided must be an int-type number, received " + num.GetType() + " instead"); } return new ContextSpecHash(rawSpecs, num.AsInt32(), preallocateStr != null); } // categorized if (ctx.createContextGroupItem() != null) { IList<EsperEPL2GrammarParser.CreateContextGroupItemContext> grps = ctx.createContextGroupItem(); IList<ContextSpecCategoryItem> items = new List<ContextSpecCategoryItem>(); foreach (var grp in grps) { var exprNode = ASTExprHelper.ExprCollectSubNodes(grp, 0, astExprNodeMap)[0]; var name = grp.i.Text; items.Add(new ContextSpecCategoryItem(exprNode, name)); } var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(ctx.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); return new ContextSpecCategory(items, filterSpec); } throw new IllegalStateException("Unrecognized context detail type"); }
public static OutputLimitSpec BuildOutputLimitSpec( CommonTokenStream tokenStream, EsperEPL2GrammarParser.OutputLimitContext ctx, IDictionary<ITree, ExprNode> astExprNodeMap) { var displayLimit = OutputLimitLimitType.DEFAULT; if (ctx.k != null) { switch (ctx.k.Type) { case EsperEPL2GrammarParser.FIRST: displayLimit = OutputLimitLimitType.FIRST; break; case EsperEPL2GrammarParser.LAST: displayLimit = OutputLimitLimitType.LAST; break; case EsperEPL2GrammarParser.SNAPSHOT: displayLimit = OutputLimitLimitType.SNAPSHOT; break; case EsperEPL2GrammarParser.ALL: displayLimit = OutputLimitLimitType.ALL; break; default: throw ASTWalkException.From("Encountered unrecognized token " + ctx.k.Text, tokenStream, ctx); } } // next is a variable, or time period, or number string variableName = null; double? rate = null; ExprNode whenExpression = null; IList<ExprNode> crontabScheduleSpec = null; IList<OnTriggerSetAssignment> thenExpressions = null; ExprTimePeriod timePeriodExpr = null; OutputLimitRateType rateType; ExprNode andAfterTerminateExpr = null; IList<OnTriggerSetAssignment> andAfterTerminateSetExpressions = null; if (ctx.t != null) { rateType = OutputLimitRateType.TERM; if (ctx.expression() != null) { andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0]; } if (ctx.onSetExpr() != null) { andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap); } } else if (ctx.wh != null) { rateType = OutputLimitRateType.WHEN_EXPRESSION; whenExpression = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0]; if (ctx.onSetExpr() != null) { thenExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap); } } else if (ctx.at != null) { rateType = OutputLimitRateType.CRONTAB; crontabScheduleSpec = ASTExprHelper.ExprCollectSubNodes(ctx.crontabLimitParameterSet(), 0, astExprNodeMap); } else { if (ctx.ev != null) { rateType = ctx.e != null ? OutputLimitRateType.EVENTS : OutputLimitRateType.TIME_PERIOD; if (ctx.i != null) { variableName = ctx.i.Text; } else if (ctx.timePeriod() != null) { timePeriodExpr = (ExprTimePeriod) ASTExprHelper.ExprCollectSubNodes(ctx.timePeriod(), 0, astExprNodeMap)[0]; } else { ASTExprHelper.ExprCollectSubNodes(ctx.number(), 0, astExprNodeMap); // remove rate = ctx.number().GetText().AsDouble(); } } else { rateType = OutputLimitRateType.AFTER; } } // get the AFTER time period ExprTimePeriod afterTimePeriodExpr = null; int? afterNumberOfEvents = null; if (ctx.outputLimitAfter() != null) { if (ctx.outputLimitAfter().timePeriod() != null) { ExprNode expression = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAfter(), 0, astExprNodeMap)[0]; afterTimePeriodExpr = (ExprTimePeriod) expression; } else { var constant = ASTConstantHelper.Parse(ctx.outputLimitAfter().number()); afterNumberOfEvents = constant.AsInt32(); } } var andAfterTerminate = false; if (ctx.outputLimitAndTerm() != null) { andAfterTerminate = true; if (ctx.outputLimitAndTerm().expression() != null) { andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAndTerm().expression(), 0, astExprNodeMap)[0]; } if (ctx.outputLimitAndTerm().onSetExpr() != null) { andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments( ctx.outputLimitAndTerm().onSetExpr().onSetAssignmentList(), astExprNodeMap); } } return new OutputLimitSpec( rate, variableName, rateType, displayLimit, whenExpression, thenExpressions, crontabScheduleSpec, timePeriodExpr, afterTimePeriodExpr, afterNumberOfEvents, andAfterTerminate, andAfterTerminateExpr, andAfterTerminateSetExpressions); }