Antlr4.Runtime.Misc.IntervalSet.Remove C# (CSharp) Method

Remove() public method

public Remove ( int el ) : void
el int
return void
        public virtual void Remove(int el)
        {
            if (@readonly)
            {
                throw new InvalidOperationException("can't alter readonly IntervalSet");
            }
            int n = intervals.Count;
            for (int i = 0; i < n; i++)
            {
                Interval I = intervals[i];
                int a = I.a;
                int b = I.b;
                if (el < a)
                {
                    break;
                }
                // list is sorted and el is before this interval; not here
                // if whole interval x..x, rm
                if (el == a && el == b)
                {
                    intervals.RemoveAt(i);
                    break;
                }
                // if on left edge x..b, adjust left
                if (el == a)
                {
                    intervals[i] = Interval.Of(I.a + 1, I.b);
                    break;
                }
                // if on right edge a..x, adjust right
                if (el == b)
                {
                    intervals[i] = Interval.Of(I.a, I.b - 1);
                    break;
                }
                // if in middle a..x..b, split interval
                if (el > a && el < b)
                {
                    // found in this interval
                    int oldb = I.b;
                    intervals[i] = Interval.Of(I.a, el - 1);
                    // [a..x-1]
                    Add(el + 1, oldb);
                }
            }
        }

Usage Example

 protected internal virtual IntervalSet GetErrorRecoverySet(Parser recognizer)
 {
     ATN atn = recognizer.Interpreter.atn;
     RuleContext ctx = recognizer._ctx;
     IntervalSet recoverSet = new IntervalSet();
     while (ctx != null && ctx.invokingState >= 0)
     {
         // compute what follows who invoked us
         ATNState invokingState = atn.states[ctx.invokingState];
         RuleTransition rt = (RuleTransition)invokingState.Transition(0);
         IntervalSet follow = atn.NextTokens(rt.followState);
         recoverSet.AddAll(follow);
         ctx = ctx.parent;
     }
     recoverSet.Remove(TokenConstants.Epsilon);
     //		System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
     return recoverSet;
 }
All Usage Examples Of Antlr4.Runtime.Misc.IntervalSet::Remove