use of org.antlr.v4.runtime.FailedPredicateException in project ballerina by ballerina-lang.
the class BallerinaParserErrorStrategy method reportError.
public void reportError(Parser parser, RecognitionException e) {
if (inErrorRecoveryMode(parser)) {
return;
}
beginErrorCondition(parser);
if (e instanceof NoViableAltException) {
reportNoViableAlternative(parser, (NoViableAltException) e);
} else if (e instanceof InputMismatchException) {
reportInputMismatch(parser, (InputMismatchException) e);
} else if (e instanceof FailedPredicateException) {
reportFailedPredicate(parser, (FailedPredicateException) e);
} else {
setContextException(parser);
DiagnosticPos pos = getPosition(getMissingSymbol(parser));
dlog.error(pos, DiagnosticCode.INVALID_TOKEN, e.getMessage());
}
}
use of org.antlr.v4.runtime.FailedPredicateException in project checkstyle by checkstyle.
the class JavadocDetailNodeParser method parseJavadocAsDetailNode.
/**
* 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 = JavadocUtil.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.
final DescriptiveErrorListener 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, errorListener);
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, errorListener.offset);
} 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;
}
Aggregations