/** * Pop the min max stack the stream is using and union the interval into the * passed in context. Return the interval for the context * * @param ctx Context to union interval into. */ private Interval popAndHandleMinMax(IncrementalParserRuleContext ctx) { Interval interval = popCurrentMinMax(ctx); ctx.setMinMaxTokenIndex(ctx.getMinMaxTokenIndex().Union(interval)); // Returning interval is wrong because there may have been child // intervals already merged into this ctx. return(ctx.getMinMaxTokenIndex()); }
/* * This is part of the regular Parser API. The super method must be called. */ /** * The new recursion context is an unfortunate edge case for us. It reparents * the relationship between the contexts, so we need to merge intervals here. */ public override void PushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex) { // This context becomes the child IncrementalParserRuleContext previous = (IncrementalParserRuleContext)this._ctx; // The incoming context becomes the parent IncrementalParserRuleContext incLocalCtx = (IncrementalParserRuleContext)localctx; incLocalCtx.setMinMaxTokenIndex(incLocalCtx.getMinMaxTokenIndex().Union(previous.getMinMaxTokenIndex())); base.PushNewRecursionContext(localctx, state, ruleIndex); }
public void ExitEveryRule(ParserRuleContext ctx) { // On exit, we need to merge the min max into the current context, // and then merge the current context interval into our parent. // First merge with the interval on the top of the stack. IncrementalParserRuleContext incCtx = (IncrementalParserRuleContext)ctx; Interval interval = popAndHandleMinMax(incCtx); // Now merge with our parent interval. if (incCtx.Parent != null) { IncrementalParserRuleContext parentIncCtx = (IncrementalParserRuleContext)incCtx.Parent; parentIncCtx.setMinMaxTokenIndex(parentIncCtx.getMinMaxTokenIndex().Union(interval)); } }