Ejemplo n.º 1
0
            /**
             * Adjust the minimum/maximum token index that appears in a rule context. Like
             * other functions, this simply converts the token indexes from how they appear
             * in the old stream to how they would appear in the new stream.
             *
             * @param ctx Parser context to adjust.
             */
            private void adjustMinMax(IncrementalParserRuleContext ctx)
            {
                bool   changed  = false;
                int    newMin   = ctx.MinTokenIndex;
                IToken newToken = getAdjustedToken(newMin);

                if (newToken != null)
                {
                    newMin  = newToken.TokenIndex;
                    changed = true;
                }

                int newMax = ctx.MaxTokenIndex;

                newToken = getAdjustedToken(newMax);

                if (newToken != null)
                {
                    newMax  = newToken.TokenIndex;
                    changed = true;
                }

                if (changed)
                {
                    ctx.setMinMaxTokenIndex(Interval.Of(newMin, newMax));
                }
            }
Ejemplo n.º 2
0
        /**
         * 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());
        }
Ejemplo n.º 3
0
        /*
         * 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);
        }
Ejemplo n.º 4
0
        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));
            }
        }