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

项目: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);
    }

  }
}
项目: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);
}
项目: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();
    }
}
项目: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 reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e)
{
    String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()];
    BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e);
    //      exception.token = this.getGrammarToken(e.getOffendingToken());
    exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

    throw exception;
}
项目:kalang    文件:AntlrErrorString.java   
public static String failedPredicate(FailedPredicateException e) {
    String ruleName = e.getRecognizer().getRuleNames()[e.getRuleIndex()];
    return "rule<" + ruleName + ">:" + e.getMessage();
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
protected String createFailedPredicateErrorMessage(Parser recognizer,
                                                   FailedPredicateException e) {
    return e.getMessage();
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
protected void reportFailedPredicate(Parser recognizer,
                                     FailedPredicateException e) {
    notifyErrorListeners(recognizer, this.createFailedPredicateErrorMessage(recognizer, e), e);
}
项目:infix    文件:FixRulesErrorStrategy.java   
/**
 * @see DefaultErrorStrategy#reportFailedPredicate
 */
@Override
protected void reportFailedPredicate(Parser recognizer, FailedPredicateException e) {
    super.reportFailedPredicate(recognizer, e);
}
项目:checkstyle    文件:JavadocDetailNodeParser.java   
/**
 * Parses Javadoc comment as DetailNode tree.
 * @param javadocCommentAst
 *        DetailAST of Javadoc comment
 * @return DetailNode tree of Javadoc comment
 */
public ParseStatus parseJavadocAsDetailNode(DetailAST javadocCommentAst) {
    blockCommentLineNumber = javadocCommentAst.getLineNo();

    final String javadocComment = JavadocUtils.getJavadocCommentContent(javadocCommentAst);

    // Use a new error listener each time to be able to use
    // one check instance for multiple files to be checked
    // without getting side effects.
    errorListener = new DescriptiveErrorListener();

    // Log messages should have line number in scope of file,
    // not in scope of Javadoc comment.
    // Offset is line number of beginning of Javadoc comment.
    errorListener.setOffset(javadocCommentAst.getLineNo() - 1);

    final ParseStatus result = new ParseStatus();

    try {
        final JavadocParser javadocParser = createJavadocParser(javadocComment);

        final ParseTree javadocParseTree = javadocParser.javadoc();

        final DetailNode tree = convertParseTreeToDetailNode(javadocParseTree);
        // adjust first line to indent of /**
        adjustFirstLineToJavadocIndent(tree,
                    javadocCommentAst.getColumnNo()
                            + JAVADOC_START.length());
        result.setTree(tree);
        result.firstNonTightHtmlTag = getFirstNonTightHtmlTag(javadocParser);
    }
    catch (ParseCancellationException | IllegalArgumentException ex) {
        ParseErrorMessage parseErrorMessage = null;

        if (ex.getCause() instanceof FailedPredicateException
                || ex.getCause() instanceof NoViableAltException) {
            final RecognitionException recognitionEx = (RecognitionException) ex.getCause();
            if (recognitionEx.getCtx() instanceof JavadocParser.HtmlTagContext) {
                final Token htmlTagNameStart = getMissedHtmlTag(recognitionEx);
                parseErrorMessage = new ParseErrorMessage(
                        errorListener.offset + htmlTagNameStart.getLine(),
                        MSG_JAVADOC_MISSED_HTML_CLOSE,
                        htmlTagNameStart.getCharPositionInLine(),
                        htmlTagNameStart.getText());
            }
        }

        if (parseErrorMessage == null) {
            // If syntax error occurs then message is printed by error listener
            // and parser throws this runtime exception to stop parsing.
            // Just stop processing current Javadoc comment.
            parseErrorMessage = errorListener.getErrorMessage();
        }

        result.setParseErrorMessage(parseErrorMessage);
    }

    return result;
}