Java 类org.antlr.v4.runtime.NoViableAltException 实例源码

项目:rapidminer    文件:CapitulatingErrorStrategy.java   
@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);
}
项目:elasticsearch_my    文件:ParserErrorStrategy.java   
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
    final Token token = re.getOffendingToken();
    String message;

    if (token == null) {
        message = "no parse token found.";
    } else if (re instanceof InputMismatchException) {
        message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
                " was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
    } else if (re instanceof NoViableAltException) {
        if (token.getType() == PainlessParser.EOF) {
            message = "unexpected end of script.";
        } else {
            message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
        }
    } else {
        message =  "unexpected token near [" + getTokenErrorDisplay(token) + "].";
    }

    Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message, re));
}
项目:ksql    文件:KsqlParserErrorStrategy.java   
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);
    }

  }
}
项目:ksql    文件:KsqlParserErrorStrategy.java   
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);
}
项目:rapidminer-studio    文件:CapitulatingErrorStrategy.java   
@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);
}
项目:StreamCQL    文件:CQLErrorStrategy.java   
/**
 * {@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);
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
@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);
}
项目:Scratch-ApuC    文件:ParserATNSimulator.java   
/** Used for debugging in adaptivePredict around execATN but I cut
 *  it out for clarity now that alg. works well. We can leave this
 *  "dead" code for a bit.
 */
public void dumpDeadEndConfigs(@NotNull NoViableAltException nvae) {
    System.err.println("dead end configs: ");
    for (ATNConfig c : nvae.getDeadEndConfigs()) {
        String trans = "no edges";
        if ( c.state.getNumberOfTransitions()>0 ) {
            Transition t = c.state.transition(0);
            if ( t instanceof AtomTransition) {
                AtomTransition at = (AtomTransition)t;
                trans = "Atom "+getTokenName(at.label);
            }
            else if ( t instanceof SetTransition ) {
                SetTransition st = (SetTransition)t;
                boolean not = st instanceof NotSetTransition;
                trans = (not?"~":"")+"Set "+st.set.toString();
            }
        }
        System.err.println(c.toString(parser, true)+":"+trans);
    }
}
项目:freelib-edtf    文件:ParserErrorListener.java   
public void syntaxError(Recognizer<?, ?> aRecognizer,
        Object aOffendingSymbol, int aLine, int aCharIndex,
        String aMessage, RecognitionException aException) {
    ANTLRErrorStrategy errorHandler = myParser.getErrorHandler();

    if (LOGGER.isWarnEnabled()) {
        LOGGER.warn(aMessage + " [" + aLine + ":" + aCharIndex + "]");
    }

    /*
     * Setting the lexer exception in the parser since I don't see a
     * getNumberOfSyntaxErrors() method in the lexer (like in antlr3) and
     * the lexer's errors aren't being reported by parser's method
     * 
     * I may just be missing the correct way this should be handled(?)
     */
    if (aException instanceof LexerNoViableAltException) {
        NoViableAltException exception = new NoViableAltException(myParser);
        errorHandler.reportError(myParser, exception);
    }
    else {
        errorHandler.reportError(myParser, aException);
    }
}
项目:kalang    文件:AntlrErrorString.java   
public static String noViableAlt(Parser recognizer, NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input = null;
    if (tokens != null) {
        Token startToken = e.getStartToken();
        if (startToken.getType() == Token.EOF) {
            input = "<EOF>";
        } else {
            input = tokens.getText(
                    startToken, e.getOffendingToken()
            );
        }
    }
    return "syntax error at input:" + input;
}
项目:kalang    文件:AntlrErrorString.java   
public static String exceptionString(Parser parser, RecognitionException ex) {
    if (ex instanceof FailedPredicateException) {
        return failedPredicate((FailedPredicateException) ex);
    } else if (ex instanceof InputMismatchException) {
        return inputMismatch((InputMismatchException) ex);
    } else if (ex instanceof NoViableAltException) {
        return noViableAlt(parser, (NoViableAltException) ex);
    } else {
        System.err.println("unknown recognition exception:" + ex);
        return ex.toString();
    }
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Specparam_assignmentContext specparam_assignment() throws RecognitionException {
    Specparam_assignmentContext _localctx = new Specparam_assignmentContext(_ctx, getState());
    enterRule(_localctx, 126, RULE_specparam_assignment);
    try {
        setState(1541);
        switch (_input.LA(1)) {
        case Escaped_identifier:
        case Simple_identifier:
            enterOuterAlt(_localctx, 1);
            {
            setState(1536);
            specparam_identifier();
            setState(1537);
            match(T__50);
            setState(1538);
            constant_mintypmax_expression();
            }
            break;
        case T__62:
            enterOuterAlt(_localctx, 2);
            {
            setState(1540);
            pulse_control_specparam();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Arrayed_identifierContext arrayed_identifier() throws RecognitionException {
    Arrayed_identifierContext _localctx = new Arrayed_identifierContext(_ctx, getState());
    enterRule(_localctx, 526, RULE_arrayed_identifier);
    try {
        setState(3834);
        switch (_input.LA(1)) {
        case Simple_identifier:
            enterOuterAlt(_localctx, 1);
            {
            setState(3832);
            simple_arrayed_identifier();
            }
            break;
        case Escaped_identifier:
            enterOuterAlt(_localctx, 2);
            {
            setState(3833);
            escaped_arrayed_identifier();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Hierarchical_identifierContext hierarchical_identifier() throws RecognitionException {
    Hierarchical_identifierContext _localctx = new Hierarchical_identifierContext(_ctx, getState());
    enterRule(_localctx, 556, RULE_hierarchical_identifier);
    try {
        setState(3876);
        switch (_input.LA(1)) {
        case Simple_identifier:
            enterOuterAlt(_localctx, 1);
            {
            setState(3874);
            simple_hierarchical_identifier();
            }
            break;
        case Escaped_identifier:
            enterOuterAlt(_localctx, 2);
            {
            setState(3875);
            escaped_hierarchical_identifier();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:UMLS-Terminology-Server    文件:ExpressionConstraintParser.java   
/**
 * Expressioncomparisonoperator.
 *
 * @return the expressioncomparisonoperator context
 * @throws RecognitionException the recognition exception
 */
public final ExpressioncomparisonoperatorContext expressioncomparisonoperator() throws RecognitionException {
    ExpressioncomparisonoperatorContext _localctx = new ExpressioncomparisonoperatorContext(_ctx, getState());
    enterRule(_localctx, 78, RULE_expressioncomparisonoperator);
    try {
        setState(423);
        switch (_input.LA(1)) {
        case EQUALS:
            enterOuterAlt(_localctx, 1);
            {
            setState(420);
            match(EQUALS);
            }
            break;
        case EXCLAMATION:
            enterOuterAlt(_localctx, 2);
            {
            {
            setState(421);
            match(EXCLAMATION);
            setState(422);
            match(EQUALS);
            }
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:UMLS-Terminology-Server    文件:ExpressionConstraintParser.java   
/**
 * Stringcomparisonoperator.
 *
 * @return the stringcomparisonoperator context
 * @throws RecognitionException the recognition exception
 */
public final StringcomparisonoperatorContext stringcomparisonoperator() throws RecognitionException {
    StringcomparisonoperatorContext _localctx = new StringcomparisonoperatorContext(_ctx, getState());
    enterRule(_localctx, 82, RULE_stringcomparisonoperator);
    try {
        setState(439);
        switch (_input.LA(1)) {
        case EQUALS:
            enterOuterAlt(_localctx, 1);
            {
            setState(436);
            match(EQUALS);
            }
            break;
        case EXCLAMATION:
            enterOuterAlt(_localctx, 2);
            {
            {
            setState(437);
            match(EXCLAMATION);
            setState(438);
            match(EQUALS);
            }
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:JuliaDT    文件:ErrorHandler.java   
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException exception) {
  super.reportNoViableAlternative(recognizer, exception);
  final Token offendingToken = exception.getOffendingToken();
  problemReporter.reportProblem(new DefaultProblem(exception.getInputStream().getSourceName(),
      exception.getMessage(), JuliaProblemIdentifier.SYNTAX_ERROR, new String[] { exception
          .getMessage() }, ProblemSeverity.DEFAULT, offendingToken.getStartIndex(),
      offendingToken.getStopIndex(), offendingToken.getLine(), offendingToken
          .getCharPositionInLine()));

}
项目:groovy    文件:DescriptiveErrorStrategy.java   
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);
}
项目:jetbrains    文件:SyntaxError.java   
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;
}
项目:Oscar    文件:tlvParser.java   
public final SnmpTypeContext snmpType() throws RecognitionException {
    SnmpTypeContext _localctx = new SnmpTypeContext(_ctx, getState());
    enterRule(_localctx, 22, RULE_snmpType);
    try {
        enterOuterAlt(_localctx, 1);
        {
        setState(87);
        switch (_input.LA(1)) {
        case 19:
            {
            {
            setState(85); match(19);
            }
            }
            break;
        case 18:
            {
            {
            setState(86); match(18);
            }
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:components    文件:SoqlParser.java   
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;
}
项目:components    文件:SoqlParser.java   
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;
}
项目:poly-ql    文件:QLParser.java   
public final BoolContext bool() throws RecognitionException {
    BoolContext _localctx = new BoolContext(_ctx, getState());
    enterRule(_localctx, 12, RULE_bool);
    try {
        setState(105);
        switch (_input.LA(1)) {
            case TRUE:
                _localctx = new TrueContext(_localctx);
                enterOuterAlt(_localctx, 1);
            {
                setState(103);
                match(TRUE);
            }
            break;
            case FALSE:
                _localctx = new FalseContext(_localctx);
                enterOuterAlt(_localctx, 2);
            {
                setState(104);
                match(FALSE);
            }
            break;
            default:
                throw new NoViableAltException(this);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:org.pshdl    文件:PSHDLLang.java   
public final PsValueContext psValue() throws RecognitionException {
    final PsValueContext _localctx = new PsValueContext(_ctx, getState());
    enterRule(_localctx, 28, RULE_psValue);
    try {
        setState(403);
        _errHandler.sync(this);
        switch (_input.LA(1)) {
        case RULE_PS_LITERAL_TERMINAL:
            enterOuterAlt(_localctx, 1); {
            setState(400);
            match(RULE_PS_LITERAL_TERMINAL);
        }
            break;
        case CLK:
        case RST:
        case RULE_ID:
            enterOuterAlt(_localctx, 2); {
            setState(401);
            psVariableRef();
        }
            break;
        case RULE_STRING:
            enterOuterAlt(_localctx, 3); {
            setState(402);
            match(RULE_STRING);
        }
            break;
        default:
            throw new NoViableAltException(this);
        }
    } catch (final RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:org.pshdl    文件:PSHDLLang.java   
public final PsFunctionDeclarationContext psFunctionDeclaration() throws RecognitionException {
    final PsFunctionDeclarationContext _localctx = new PsFunctionDeclarationContext(_ctx, getState());
    enterRule(_localctx, 48, RULE_psFunctionDeclaration);
    try {
        setState(478);
        _errHandler.sync(this);
        switch (_input.LA(1)) {
        case SIMULATION:
        case NATIVE:
            enterOuterAlt(_localctx, 1); {
            setState(475);
            psNativeFunction();
        }
            break;
        case INLINE:
            enterOuterAlt(_localctx, 2); {
            setState(476);
            psInlineFunction();
        }
            break;
        case SUBSTITUTE:
            enterOuterAlt(_localctx, 3); {
            setState(477);
            psSubstituteFunction();
        }
            break;
        default:
            throw new NoViableAltException(this);
        }
    } catch (final RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:org.pshdl    文件:PSHDLLang.java   
public final PsCompoundStatementContext psCompoundStatement() throws RecognitionException {
    final PsCompoundStatementContext _localctx = new PsCompoundStatementContext(_ctx, getState());
    enterRule(_localctx, 78, RULE_psCompoundStatement);
    try {
        setState(650);
        _errHandler.sync(this);
        switch (_input.LA(1)) {
        case IF:
            enterOuterAlt(_localctx, 1); {
            setState(647);
            psIfStatement();
        }
            break;
        case FOR:
            enterOuterAlt(_localctx, 2); {
            setState(648);
            psForStatement();
        }
            break;
        case SWITCH:
            enterOuterAlt(_localctx, 3); {
            setState(649);
            psSwitchStatement();
        }
            break;
        default:
            throw new NoViableAltException(this);
        }
    } catch (final RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:org.pshdl    文件:PSHDLLang.java   
public final PsTypeDeclarationContext psTypeDeclaration() throws RecognitionException {
    final PsTypeDeclarationContext _localctx = new PsTypeDeclarationContext(_ctx, getState());
    enterRule(_localctx, 94, RULE_psTypeDeclaration);
    try {
        setState(733);
        _errHandler.sync(this);
        switch (_input.LA(1)) {
        case INTERFACE:
            enterOuterAlt(_localctx, 1); {
            setState(731);
            psInterfaceDeclaration();
        }
            break;
        case ENUM:
            enterOuterAlt(_localctx, 2); {
            setState(732);
            psEnumDeclaration();
        }
            break;
        default:
            throw new NoViableAltException(this);
        }
    } catch (final RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:org.pshdl    文件:PSHDLLang.java   
public final PsArrayContext psArray() throws RecognitionException {
    final PsArrayContext _localctx = new PsArrayContext(_ctx, getState());
    enterRule(_localctx, 110, RULE_psArray);
    try {
        int _alt;
        enterOuterAlt(_localctx, 1);
        {
            setState(846);
            _errHandler.sync(this);
            _alt = 1;
            do {
                switch (_alt) {
                case 1: {
                    {
                        setState(842);
                        match(BRACKET_OPEN);
                        setState(843);
                        psExpression(0);
                        setState(844);
                        match(BRACKET_CLOSE);
                    }
                }
                    break;
                default:
                    throw new NoViableAltException(this);
                }
                setState(848);
                _errHandler.sync(this);
                _alt = getInterpreter().adaptivePredict(_input, 105, _ctx);
            } while ((_alt != 2) && (_alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER));
        }
    } catch (final RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
项目:Scratch-ApuC    文件:ParserATNSimulator.java   
@NotNull
protected NoViableAltException noViableAlt(@NotNull TokenStream input,
                                        @NotNull ParserRuleContext outerContext,
                                        @NotNull ATNConfigSet configs,
                                        int startIndex)
{
    return new NoViableAltException(parser, input,
                                        input.get(startIndex),
                                        input.LT(1),
                                        configs, outerContext);
}
项目:beetl2.0    文件:BeetlAntlrErrorStrategy.java   
@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;
    }
}
项目:beetl2.0    文件:BeetlAntlrErrorStrategy.java   
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;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final PortContext port() throws RecognitionException {
    PortContext _localctx = new PortContext(_ctx, getState());
    enterRule(_localctx, 32, RULE_port);
    int _la;
    try {
        setState(811);
        switch (_input.LA(1)) {
        case T__16:
        case T__17:
        case T__18:
        case Escaped_identifier:
        case Simple_identifier:
            enterOuterAlt(_localctx, 1);
            {
            setState(801);
            _la = _input.LA(1);
            if (_la==T__18 || _la==Escaped_identifier || _la==Simple_identifier) {
                {
                setState(800);
                port_expression();
                }
            }

            }
            break;
        case T__4:
            enterOuterAlt(_localctx, 2);
            {
            setState(803);
            match(T__4);
            setState(804);
            port_identifier();
            setState(805);
            match(T__15);
            setState(807);
            _la = _input.LA(1);
            if (_la==T__18 || _la==Escaped_identifier || _la==Simple_identifier) {
                {
                setState(806);
                port_expression();
                }
            }

            setState(809);
            match(T__17);
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Port_expressionContext port_expression() throws RecognitionException {
    Port_expressionContext _localctx = new Port_expressionContext(_ctx, getState());
    enterRule(_localctx, 34, RULE_port_expression);
    int _la;
    try {
        setState(825);
        switch (_input.LA(1)) {
        case Escaped_identifier:
        case Simple_identifier:
            enterOuterAlt(_localctx, 1);
            {
            setState(813);
            port_reference();
            }
            break;
        case T__18:
            enterOuterAlt(_localctx, 2);
            {
            setState(814);
            match(T__18);
            setState(815);
            port_reference();
            setState(820);
            _errHandler.sync(this);
            _la = _input.LA(1);
            while (_la==T__16) {
                {
                {
                setState(816);
                match(T__16);
                setState(817);
                port_reference();
                }
                }
                setState(822);
                _errHandler.sync(this);
                _la = _input.LA(1);
            }
            setState(823);
            match(T__19);
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Function_item_declarationContext function_item_declaration() throws RecognitionException {
    Function_item_declarationContext _localctx = new Function_item_declarationContext(_ctx, getState());
    enterRule(_localctx, 142, RULE_function_item_declaration);
    try {
        setState(1643);
        switch (_input.LA(1)) {
        case T__15:
        case T__23:
        case T__25:
        case T__26:
        case T__27:
        case T__28:
        case T__29:
        case T__34:
        case T__35:
            enterOuterAlt(_localctx, 1);
            {
            setState(1639);
            block_item_declaration();
            }
            break;
        case T__31:
        case T__32:
        case T__33:
            enterOuterAlt(_localctx, 2);
            {
            setState(1640);
            tf_declaration();
            setState(1641);
            match(T__1);
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Range_or_typeContext range_or_type() throws RecognitionException {
    Range_or_typeContext _localctx = new Range_or_typeContext(_ctx, getState());
    enterRule(_localctx, 148, RULE_range_or_type);
    try {
        setState(1666);
        switch (_input.LA(1)) {
        case T__20:
            enterOuterAlt(_localctx, 1);
            {
            setState(1661);
            range();
            }
            break;
        case T__25:
            enterOuterAlt(_localctx, 2);
            {
            setState(1662);
            match(T__25);
            }
            break;
        case T__26:
            enterOuterAlt(_localctx, 3);
            {
            setState(1663);
            match(T__26);
            }
            break;
        case T__27:
            enterOuterAlt(_localctx, 4);
            {
            setState(1664);
            match(T__27);
            }
            break;
        case T__28:
            enterOuterAlt(_localctx, 5);
            {
            setState(1665);
            match(T__28);
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Delay_or_event_controlContext delay_or_event_control() throws RecognitionException {
    Delay_or_event_controlContext _localctx = new Delay_or_event_controlContext(_ctx, getState());
    enterRule(_localctx, 294, RULE_delay_or_event_control);
    try {
        setState(2633);
        switch (_input.LA(1)) {
        case T__14:
            enterOuterAlt(_localctx, 1);
            {
            setState(2625);
            delay_control();
            }
            break;
        case T__116:
            enterOuterAlt(_localctx, 2);
            {
            setState(2626);
            event_control();
            }
            break;
        case T__114:
            enterOuterAlt(_localctx, 3);
            {
            setState(2627);
            match(T__114);
            setState(2628);
            match(T__15);
            setState(2629);
            expression();
            setState(2630);
            match(T__17);
            setState(2631);
            event_control();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Event_expressionContext event_expression() throws RecognitionException {
    Event_expressionContext _localctx = new Event_expressionContext(_ctx, getState());
    enterRule(_localctx, 304, RULE_event_expression);
    int _la;
    try {
        enterOuterAlt(_localctx, 1);
        {
        setState(2673);
        event_primary();
        setState(2680);
        _errHandler.sync(this);
        _la = _input.LA(1);
        while (_la==T__16 || _la==T__84) {
            {
            setState(2678);
            switch (_input.LA(1)) {
            case T__84:
                {
                setState(2674);
                match(T__84);
                setState(2675);
                event_primary();
                }
                break;
            case T__16:
                {
                setState(2676);
                match(T__16);
                setState(2677);
                event_primary();
                }
                break;
            default:
                throw new NoViableAltException(this);
            }
            }
            setState(2682);
            _errHandler.sync(this);
            _la = _input.LA(1);
        }
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Event_primaryContext event_primary() throws RecognitionException {
    Event_primaryContext _localctx = new Event_primaryContext(_ctx, getState());
    enterRule(_localctx, 306, RULE_event_primary);
    try {
        enterOuterAlt(_localctx, 1);
        {
        setState(2688);
        switch (_input.LA(1)) {
        case T__15:
        case T__18:
        case T__135:
        case T__136:
        case T__140:
        case T__141:
        case T__142:
        case T__143:
        case T__144:
        case T__145:
        case T__146:
        case T__147:
        case T__148:
        case Real_number:
        case Decimal_number:
        case Binary_number:
        case Octal_number:
        case Hex_number:
        case String:
        case Escaped_identifier:
        case Simple_identifier:
        case Dollar_Identifier:
            {
            setState(2683);
            expression();
            }
            break;
        case T__119:
            {
            setState(2684);
            match(T__119);
            setState(2685);
            expression();
            }
            break;
        case T__120:
            {
            setState(2686);
            match(T__120);
            setState(2687);
            expression();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Specify_itemContext specify_item() throws RecognitionException {
    Specify_itemContext _localctx = new Specify_itemContext(_ctx, getState());
    enterRule(_localctx, 338, RULE_specify_item);
    try {
        setState(2982);
        switch (_input.LA(1)) {
        case T__30:
            enterOuterAlt(_localctx, 1);
            {
            setState(2978);
            specparam_declaration();
            }
            break;
        case T__128:
        case T__129:
            enterOuterAlt(_localctx, 2);
            {
            setState(2979);
            pulsestyle_declaration();
            }
            break;
        case T__130:
        case T__131:
            enterOuterAlt(_localctx, 3);
            {
            setState(2980);
            showcancelled_declaration();
            }
            break;
        case T__15:
        case T__98:
        case T__134:
        case Escaped_identifier:
        case Simple_identifier:
            enterOuterAlt(_localctx, 4);
            {
            setState(2981);
            path_declaration();
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
项目:netlist-graph    文件:Verilog2001Parser.java   
public final Pulsestyle_declarationContext pulsestyle_declaration() throws RecognitionException {
    Pulsestyle_declarationContext _localctx = new Pulsestyle_declarationContext(_ctx, getState());
    enterRule(_localctx, 340, RULE_pulsestyle_declaration);
    try {
        setState(2992);
        switch (_input.LA(1)) {
        case T__128:
            enterOuterAlt(_localctx, 1);
            {
            setState(2984);
            match(T__128);
            setState(2985);
            list_of_path_outputs();
            setState(2986);
            match(T__1);
            }
            break;
        case T__129:
            enterOuterAlt(_localctx, 2);
            {
            setState(2988);
            match(T__129);
            setState(2989);
            list_of_path_outputs();
            setState(2990);
            match(T__1);
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}