Search in sources :

Example 6 with org.antlr.v4.parse.v3TreeGrammarException

use of org.antlr.v4.parse.v3TreeGrammarException in project CFLint by cflint.

the class CFLint method syntaxError.

@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, int line, int charPositionInLine, final String msg, final org.antlr.v4.runtime.RecognitionException e) {
    final String file = currentFile == null ? "" : currentFile + "\r\n";
    String expression = null;
    if (offendingSymbol instanceof Token) {
        expression = ((Token) offendingSymbol).getText();
        if (expression.length() > 50) {
            expression = expression.substring(1, 40) + "...";
        }
    }
    if (currentElement != null) {
        if (line == 1) {
            line = currentElement.getSource().getRow(currentElement.getBegin());
            charPositionInLine = charPositionInLine + currentElement.getSource().getColumn(currentElement.getBegin());
        } else {
            line = currentElement.getSource().getRow(currentElement.getBegin()) + line - 1;
        }
    }
    if (recognizer instanceof Parser && ((Parser) recognizer).isExpectedToken(CFSCRIPTParser.SEMICOLON)) {
        bugs.add(new BugInfo.BugInfoBuilder().setMessageCode("MISSING_SEMI").setFilename(file).setMessage("End of statement(;) expected instead of " + expression).setSeverity("ERROR").setExpression(expression).setLine(line).setColumn(charPositionInLine).build());
    } else {
        fireCFLintException(e, PARSE_ERROR, file, line, charPositionInLine, "", msg);
    }
}
Also used : BugInfoBuilder(com.cflint.BugInfo.BugInfoBuilder) Token(org.antlr.v4.runtime.Token) CFMLParser(cfml.parsing.CFMLParser) Parser(org.antlr.v4.runtime.Parser) CFSCRIPTParser(cfml.CFSCRIPTParser)

Aggregations

NoViableAltException (org.antlr.v4.runtime.NoViableAltException)2 RecognitionException (org.antlr.v4.runtime.RecognitionException)2 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)2 Position (ast.Ast.Position)1 ErrorMessage (ast.ErrorMessage)1 ExpCore (ast.ExpCore)1 Expression (ast.Expression)1 ClassB (ast.Expression.ClassB)1 ClassReuse (ast.Expression.ClassReuse)1 CFSCRIPTParser (cfml.CFSCRIPTParser)1 CFMLParser (cfml.parsing.CFMLParser)1 BugInfoBuilder (com.cflint.BugInfo.BugInfoBuilder)1 CloneVisitor (coreVisitors.CloneVisitor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1