Exemplo n.º 1
0
 public virtual void MatchRange(int a, int b)
 {
     if (input.LA(1) < a || input.LA(1) > b)
     {
         if (state.backtracking > 0)
         {
             state.failed = true;
             return;
         }
         MismatchedRangeException mre = new MismatchedRangeException(a, b, input);
         Recover(mre);
         throw mre;
     }
     input.Consume();
     state.failed = false;
 }
Exemplo n.º 2
0
        public override string GetErrorMessage(RecognitionException e, string[] tokenNames)
        {
            string msg = null;

            if (e is MismatchedTokenException)
            {
                MismatchedTokenException mte = (MismatchedTokenException)e;
                msg = "mismatched character " + GetCharErrorDisplay(e.Character) + " expecting " + GetCharErrorDisplay(mte.Expecting);
            }
            else if (e is NoViableAltException)
            {
                NoViableAltException nvae = (NoViableAltException)e;
                // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>"
                // and "(decision="+nvae.decisionNumber+") and
                // "state "+nvae.stateNumber
                msg = "no viable alternative at character " + GetCharErrorDisplay(e.Character);
            }
            else if (e is EarlyExitException)
            {
                EarlyExitException eee = (EarlyExitException)e;
                // for development, can add "(decision="+eee.decisionNumber+")"
                msg = "required (...)+ loop did not match anything at character " + GetCharErrorDisplay(e.Character);
            }
            else if (e is MismatchedNotSetException)
            {
                MismatchedNotSetException mse = (MismatchedNotSetException)e;
                msg = "mismatched character " + GetCharErrorDisplay(e.Character) + " expecting set " + mse.Expecting;
            }
            else if (e is MismatchedSetException)
            {
                MismatchedSetException mse = (MismatchedSetException)e;
                msg = "mismatched character " + GetCharErrorDisplay(e.Character) + " expecting set " + mse.Expecting;
            }
            else if (e is MismatchedRangeException)
            {
                MismatchedRangeException mre = (MismatchedRangeException)e;
                msg = "mismatched character " + GetCharErrorDisplay(e.Character) + " expecting set " +
                      GetCharErrorDisplay(mre.A) + ".." + GetCharErrorDisplay(mre.B);
            }
            else
            {
                msg = base.GetErrorMessage(e, tokenNames);
            }
            return(msg);
        }