org.antlr.v4.runtime.NoViableAltException Java Examples

The following examples show how to use org.antlr.v4.runtime.NoViableAltException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
public void reportError(Parser recognizer, RecognitionException e) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
      this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
      this.reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
      this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
      System.err.println("unknown recognition error type: " + e.getClass().getName());
      recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
    }

  }
}
 
Example #2
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
  TokenStream tokens = recognizer.getInputStream();
  String input;
  if (tokens != null) {
    if (e.getStartToken().getType() == -1) {
      input = "<EOF>";
    } else {
      input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    }
  } else {
    input = "<unknown input>";
  }

  String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example #3
Source File: CQLErrorStrategy.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens instanceof TokenStream)
    {
        if (e.getStartToken().getType() == Token.EOF)
            input = "<EOF>";
        else
            input = getText(tokens, e.getStartToken(), e.getOffendingToken());
    }
    else
    {
        input = "<unknown input>";
    }
    String msg = "no viable alternative at input " + escapeWSAndQuote(input);
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example #4
Source File: DescriptiveErrorStrategy.java    From groovy with Apache License 2.0 6 votes vote down vote up
@Override
public void recover(Parser recognizer, RecognitionException e) {
    for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
        context.exception = e;
    }

    if (PredictionMode.LL.equals(recognizer.getInterpreter().getPredictionMode())) {
        if (e instanceof NoViableAltException) {
            this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
        } else if (e instanceof InputMismatchException) {
            this.reportInputMismatch(recognizer, (InputMismatchException) e);
        } else if (e instanceof FailedPredicateException) {
            this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
        }
    }

    throw new ParseCancellationException(e);
}
 
Example #5
Source File: CapitulatingErrorStrategy.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
	// change error message from default implementation
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens != null) {
		if (e.getStartToken().getType() == Token.EOF) {
			input = "the end";
		} else {
			input = escapeWSAndQuote(tokens.getText(e.getStartToken(), e.getOffendingToken()));
		}
	} else {
		input = escapeWSAndQuote("<unknown input>");
	}
	String msg = "inadmissible input at " + input;
	recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example #6
Source File: BeetlAntlrErrorStrategy.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens instanceof TokenStream)
	{
		if (e.getStartToken().getType() == Token.EOF)
			input = "<文件尾>";
		else
			input = tokens.getText(e.getStartToken(), e.getOffendingToken());
	}
	else
	{
		input = "<未知输入>";
	}
	BeetlException exception = null;
	if(keys.contains(e.getOffendingToken().getText())){
		 exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
					"不允许"+e.getOffendingToken().getText()+"关键出现在这里"+":"+escapeWSAndQuote(input), e);
	}else{
		exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
				escapeWSAndQuote(input), e);
	}
	//		String msg = "no viable alternative at input " + escapeWSAndQuote(input);

	exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

	throw exception;
}
 
Example #7
Source File: BeetlAntlrErrorStrategy.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void reportError(Parser recognizer, RecognitionException e)
{
	// if we've already reported an error and have not matched a token
	// yet successfully, don't report any errors.
	if (inErrorRecoveryMode(recognizer))
	{
		//			System.err.print("[SPURIOUS] ");
		return; // don't report spurious errors
	}
	beginErrorCondition(recognizer);
	if (e instanceof NoViableAltException)
	{
		reportNoViableAlternative(recognizer, (NoViableAltException) e);
	}
	else if (e instanceof InputMismatchException)
	{
		reportInputMismatch(recognizer, (InputMismatchException) e);
	}
	else if (e instanceof FailedPredicateException)
	{
		reportFailedPredicate(recognizer, (FailedPredicateException) e);
	}
	else
	{
		//			System.err.println("unknown recognition error type: " + e.getClass().getName());
		BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
		//			exception.token = this.getGrammarToken(e.getOffendingToken());
		exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

		throw exception;
	}
}
 
Example #8
Source File: SoqlParser.java    From components with Apache License 2.0 5 votes vote down vote up
public final AnywordContext anyword() throws RecognitionException {
	AnywordContext _localctx = new AnywordContext(_ctx, getState());
	enterRule(_localctx, 22, RULE_anyword);
	try {
		int _alt;
		enterOuterAlt(_localctx, 1);
		{
			setState(86);
			_errHandler.sync(this);
			_alt = 1;
			do {
				switch (_alt) {
				case 1: {
					{
						setState(85);
						match(ANYCHAR);
					}
				}
					break;
				default:
					throw new NoViableAltException(this);
				}
				setState(88);
				_errHandler.sync(this);
				_alt = getInterpreter().adaptivePredict(_input, 8, _ctx);
			} while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
		}
	} catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	} finally {
		exitRule();
	}
	return _localctx;
}
 
Example #9
Source File: SoqlParser.java    From components with Apache License 2.0 5 votes vote down vote up
public final ObjectPrefixContext objectPrefix() throws RecognitionException {
	ObjectPrefixContext _localctx = new ObjectPrefixContext(_ctx, getState());
	enterRule(_localctx, 16, RULE_objectPrefix);
	try {
		int _alt;
		enterOuterAlt(_localctx, 1);
		{
			setState(73);
			_errHandler.sync(this);
			_alt = 1;
			do {
				switch (_alt) {
				case 1: {
					{
						setState(71);
						match(NAME);
						setState(72);
						match(DOT);
					}
				}
					break;
				default:
					throw new NoViableAltException(this);
				}
				setState(75);
				_errHandler.sync(this);
				_alt = getInterpreter().adaptivePredict(_input, 7, _ctx);
			} while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
		}
	} catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	} finally {
		exitRule();
	}
	return _localctx;
}
 
Example #10
Source File: DescriptiveErrorStrategy.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected String createNoViableAlternativeErrorMessage(Parser recognizer, NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens != null) {
        if (e.getStartToken().getType() == Token.EOF) {
            input = "<EOF>";
        } else {
            input = charStream.getText(Interval.of(e.getStartToken().getStartIndex(), e.getOffendingToken().getStopIndex()));
        }
    } else {
        input = "<unknown input>";
    }

    return "Unexpected input: " + escapeWSAndQuote(input);
}
 
Example #11
Source File: SyntaxError.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Token getOffendingSymbol() {
	if ( e instanceof NoViableAltException ) {
		// the error node in parse tree will have the start token as bad token
		// even if many lookahead tokens were matched before failing to find
		// a viable alt.
		return ((NoViableAltException) e).getStartToken();
	}
	return offendingSymbol;
}
 
Example #12
Source File: JavascriptParserErrorStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the ANTLR parser will throw an exception after the first error
 *
 * @param recognizer the parser being used
 * @param re the original exception from the parser
 */
@Override
public void recover(Parser recognizer, RecognitionException re) {
  Token token = re.getOffendingToken();
  String message;

  if (token == null) {
    message = "error " + getTokenErrorDisplay(token);
  } else if (re instanceof InputMismatchException) {
     message = "unexpected token " + getTokenErrorDisplay(token) +
         " on line (" + token.getLine() + ") position (" + token.getCharPositionInLine() + ")" +
         " was expecting one of " + re.getExpectedTokens().toString(recognizer.getVocabulary());
  } else if (re instanceof NoViableAltException) {
    if (token.getType() == JavascriptParser.EOF) {
      message = "unexpected end of expression";
    } else {
      message = "invalid sequence of tokens near " + getTokenErrorDisplay(token) +
          " on line (" + token.getLine() + ") position (" + token.getCharPositionInLine() + ")";
    }
  } else {
    message = " unexpected token near " + getTokenErrorDisplay(token) +
        " on line (" + token.getLine() + ") position (" + token.getCharPositionInLine() + ")";
  }

  ParseException parseException = new ParseException(message, token.getStartIndex());
  parseException.initCause(re);
  throw new RuntimeException(parseException);
}
 
Example #13
Source File: Antlr4EqlSyntaxErrorListener.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> parser, Object offendingSymbol, int line, int column, String msg, RecognitionException e) {
	String symbol = null;

	if(e instanceof NoViableAltException) {
		NoViableAltException nvae = (NoViableAltException) e;
		symbol = nvae.getStartToken().getText();
	}
	
	this.errors.add(new EqlSyntaxError(line, column, symbol));
}
 
Example #14
Source File: FWPolicyParser.java    From development with Apache License 2.0 4 votes vote down vote up
public final PolicyContext policy(List<FWPolicy> pList)
        throws RecognitionException {
    PolicyContext _localctx = new PolicyContext(_ctx, getState(), pList);
    enterRule(_localctx, 2, RULE_policy);

    ((PolicyContext) _localctx).p = new FWPolicy();
    _localctx.p.setAction(Action.Accept);
    _localctx.p.setSrc(null);
    _localctx.p.setSrcPort("any");
    _localctx.p.setDst(null);
    _localctx.p.setDstPort("any");
    _localctx.p.setProtocol(Protocol.TCP);
    _localctx.p.setDstService("NONE");
    _localctx.p.setDstType("IP");

    int _la;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(30);
            source_zone(_localctx.p);
            setState(32);
            _la = _input.LA(1);
            if (_la == IP) {
                {
                    setState(31);
                    source_ip(_localctx.p);
                }
            }

            setState(35);
            _la = _input.LA(1);
            if (_la == PORT) {
                {
                    setState(34);
                    source_port(_localctx.p);
                }
            }

            setState(37);
            match(ARROW);
            setState(38);
            dest_zone(_localctx.p);
            setState(49);
            switch (_input.LA(1)) {
            case SERVICE: {
                setState(39);
                dest_service(_localctx.p);
            }
                break;
            case EOF:
            case SEMICOLON:
            case PROTOCOL:
            case PORT:
            case IP: {
                setState(41);
                _la = _input.LA(1);
                if (_la == IP) {
                    {
                        setState(40);
                        dest_ip(_localctx.p);
                    }
                }

                setState(44);
                _la = _input.LA(1);
                if (_la == PORT) {
                    {
                        setState(43);
                        dest_port(_localctx.p);
                    }
                }

                setState(47);
                _la = _input.LA(1);
                if (_la == PROTOCOL) {
                    {
                        setState(46);
                        protocol(_localctx.p);
                    }
                }

            }
                break;
            default:
                throw new NoViableAltException(this);
            }
        }

        _localctx.pList.add(_localctx.p);

    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
 
Example #15
Source File: XMLParser.java    From manifold with Apache License 2.0 4 votes vote down vote up
public final ContentContext content() throws RecognitionException
{
  ContentContext _localctx = new ContentContext( _ctx, getState() );
  enterRule( _localctx, 4, RULE_content );
  int _la;
  try
  {
    int _alt;
    enterOuterAlt( _localctx, 1 );
    {
      setState( 42 );
      _la = _input.LA( 1 );
      if( _la == SEA_WS || _la == TEXT )
      {
        {
          setState( 41 );
          chardata();
        }
      }

      setState( 56 );
      _errHandler.sync( this );
      _alt = getInterpreter().adaptivePredict( _input, 7, _ctx );
      while( _alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER )
      {
        if( _alt == 1 )
        {
          {
            {
              setState( 49 );
              switch( _input.LA( 1 ) )
              {
                case OPEN:
                {
                  setState( 44 );
                  element();
                }
                break;
                case EntityRef:
                case CharRef:
                {
                  setState( 45 );
                  reference();
                }
                break;
                case CDATA:
                {
                  setState( 46 );
                  match( CDATA );
                }
                break;
                case PI:
                {
                  setState( 47 );
                  match( PI );
                }
                break;
                case COMMENT:
                {
                  setState( 48 );
                  match( COMMENT );
                }
                break;
                default:
                  throw new NoViableAltException( this );
              }
              setState( 52 );
              _la = _input.LA( 1 );
              if( _la == SEA_WS || _la == TEXT )
              {
                {
                  setState( 51 );
                  chardata();
                }
              }

            }
          }
        }
        setState( 58 );
        _errHandler.sync( this );
        _alt = getInterpreter().adaptivePredict( _input, 7, _ctx );
      }
    }
  }
  catch( RecognitionException re )
  {
    _localctx.exception = re;
    _errHandler.reportError( this, re );
    _errHandler.recover( this, re );
  }
  finally
  {
    exitRule();
  }
  return _localctx;
}
 
Example #16
Source File: DescriptiveErrorStrategy.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
protected void reportNoViableAlternative(Parser recognizer,
                                         NoViableAltException e) {

    notifyErrorListeners(recognizer, this.createNoViableAlternativeErrorMessage(recognizer, e), e);
}
 
Example #17
Source File: GyroErrorStrategy.java    From gyro with Apache License 2.0 4 votes vote down vote up
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException error) {
    recognizer.notifyErrorListeners(error.getOffendingToken(), "Invalid input", error);
}
 
Example #18
Source File: SoqlParser.java    From components with Apache License 2.0 4 votes vote down vote up
public final AnythingContext anything() throws RecognitionException {
	AnythingContext _localctx = new AnythingContext(_ctx, getState());
	enterRule(_localctx, 24, RULE_anything);
	try {
		setState(97);
		_errHandler.sync(this);
		switch (_input.LA(1)) {
		case NAME:
			enterOuterAlt(_localctx, 1); {
			setState(90);
			match(NAME);
		}
			break;
		case ANYCHAR:
			enterOuterAlt(_localctx, 2); {
			setState(91);
			anyword();
		}
			break;
		case COMMA:
			enterOuterAlt(_localctx, 3); {
			setState(92);
			match(COMMA);
		}
			break;
		case DOT:
			enterOuterAlt(_localctx, 4); {
			setState(93);
			match(DOT);
		}
			break;
		case LPAR:
			enterOuterAlt(_localctx, 5); {
			setState(94);
			match(LPAR);
		}
			break;
		case RPAR:
			enterOuterAlt(_localctx, 6); {
			setState(95);
			match(RPAR);
		}
			break;
		case BY:
			enterOuterAlt(_localctx, 7); {
			setState(96);
			match(BY);
		}
			break;
		default:
			throw new NoViableAltException(this);
		}
	} catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	} finally {
		exitRule();
	}
	return _localctx;
}
 
Example #19
Source File: BatfishParserATNSimulator.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
protected NoViableAltException noViableAlt(
    TokenStream input, ParserRuleContext outerContext, ATNConfigSet configs, int startIndex) {
  _exception = super.noViableAlt(input, outerContext, configs, startIndex);
  return _exception;
}
 
Example #20
Source File: XpathParser.java    From JsoupXpath with Apache License 2.0 4 votes vote down vote up
public final LocationPathContext locationPath() throws RecognitionException {
	LocationPathContext _localctx = new LocationPathContext(_ctx, getState());
	enterRule(_localctx, 2, RULE_locationPath);
	try {
		setState(58);
		_errHandler.sync(this);
		switch (_input.LA(1)) {
		case T__0:
		case NodeType:
		case AxisName:
		case DOT:
		case MUL:
		case DOTDOT:
		case AT:
		case NCName:
			enterOuterAlt(_localctx, 1);
			{
			setState(56);
			relativeLocationPath();
			}
			break;
		case PATHSEP:
		case ABRPATH:
			enterOuterAlt(_localctx, 2);
			{
			setState(57);
			absoluteLocationPathNoroot();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
Example #21
Source File: XpathParser.java    From JsoupXpath with Apache License 2.0 4 votes vote down vote up
public final StepContext step() throws RecognitionException {
	StepContext _localctx = new StepContext(_ctx, getState());
	enterRule(_localctx, 8, RULE_step);
	int _la;
	try {
		setState(80);
		_errHandler.sync(this);
		switch (_input.LA(1)) {
		case T__0:
		case NodeType:
		case AxisName:
		case MUL:
		case AT:
		case NCName:
			enterOuterAlt(_localctx, 1);
			{
			setState(71);
			axisSpecifier();
			setState(72);
			nodeTest();
			setState(76);
			_errHandler.sync(this);
			_la = _input.LA(1);
			while (_la==LBRAC) {
				{
				{
				setState(73);
				predicate();
				}
				}
				setState(78);
				_errHandler.sync(this);
				_la = _input.LA(1);
			}
			}
			break;
		case DOT:
		case DOTDOT:
			enterOuterAlt(_localctx, 2);
			{
			setState(79);
			abbreviatedStep();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
Example #22
Source File: XpathParser.java    From JsoupXpath with Apache License 2.0 4 votes vote down vote up
public final NodeTestContext nodeTest() throws RecognitionException {
	NodeTestContext _localctx = new NodeTestContext(_ctx, getState());
	enterRule(_localctx, 12, RULE_nodeTest);
	try {
		setState(97);
		_errHandler.sync(this);
		switch (_input.LA(1)) {
		case AxisName:
		case MUL:
		case NCName:
			enterOuterAlt(_localctx, 1);
			{
			setState(89);
			nameTest();
			}
			break;
		case NodeType:
			enterOuterAlt(_localctx, 2);
			{
			setState(90);
			match(NodeType);
			setState(91);
			match(LPAR);
			setState(92);
			match(RPAR);
			}
			break;
		case T__0:
			enterOuterAlt(_localctx, 3);
			{
			setState(93);
			match(T__0);
			setState(94);
			match(LPAR);
			setState(95);
			match(Literal);
			setState(96);
			match(RPAR);
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
Example #23
Source File: XpathParser.java    From JsoupXpath with Apache License 2.0 4 votes vote down vote up
public final PrimaryExprContext primaryExpr() throws RecognitionException {
	PrimaryExprContext _localctx = new PrimaryExprContext(_ctx, getState());
	enterRule(_localctx, 20, RULE_primaryExpr);
	try {
		setState(115);
		_errHandler.sync(this);
		switch (_input.LA(1)) {
		case T__3:
			enterOuterAlt(_localctx, 1);
			{
			setState(107);
			variableReference();
			}
			break;
		case LPAR:
			enterOuterAlt(_localctx, 2);
			{
			setState(108);
			match(LPAR);
			setState(109);
			expr();
			setState(110);
			match(RPAR);
			}
			break;
		case Literal:
			enterOuterAlt(_localctx, 3);
			{
			setState(112);
			match(Literal);
			}
			break;
		case Number:
			enterOuterAlt(_localctx, 4);
			{
			setState(113);
			match(Number);
			}
			break;
		case AxisName:
		case NCName:
			enterOuterAlt(_localctx, 5);
			{
			setState(114);
			functionCall();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
Example #24
Source File: ErrorHandler.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e)
{
    try {
        Parser parser = (Parser) recognizer;

        ATN atn = parser.getATN();

        ATNState currentState;
        Token currentToken;
        RuleContext context;

        if (e != null) {
            currentState = atn.states.get(e.getOffendingState());
            currentToken = e.getOffendingToken();
            context = e.getCtx();

            if (e instanceof NoViableAltException) {
                currentToken = ((NoViableAltException) e).getStartToken();
            }
        }
        else {
            currentState = atn.states.get(parser.getState());
            currentToken = parser.getCurrentToken();
            context = parser.getContext();
        }

        Analyzer analyzer = new Analyzer(parser, specialRules, specialTokens, ignoredRules);
        Result result = analyzer.process(currentState, currentToken.getTokenIndex(), context);

        // pick the candidate tokens associated largest token index processed (i.e., the path that consumed the most input)
        String expected = result.getExpected().stream()
                .sorted()
                .collect(Collectors.joining(", "));

        message = format("mismatched input '%s'. Expecting: %s", parser.getTokenStream().get(result.getErrorTokenIndex()).getText(), expected);
    }
    catch (Exception exception) {
        LOG.error(exception, "Unexpected failure when handling parsing error. This is likely a bug in the implementation");
    }

    throw new ParsingException(message, e, line, charPositionInLine);
}
 
Example #25
Source File: GyroErrorStrategyTest.java    From gyro with Apache License 2.0 3 votes vote down vote up
@Test
void reportNoViableAlternative() {
    NoViableAltException error = mock(NoViableAltException.class);

    when(error.getOffendingToken()).thenReturn(token);

    strategy.reportNoViableAlternative(recognizer, error);

    verify(recognizer).notifyErrorListeners(token, "Invalid input", error);
}