Example usage for org.antlr.v4.runtime Parser getSourceName

List of usage examples for org.antlr.v4.runtime Parser getSourceName

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Parser getSourceName.

Prototype

public String getSourceName() 

Source Link

Usage

From source file:net.certiv.json.parser.JsonErrorListener.java

License:Open Source License

@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
        String msg, RecognitionException e) {

    Parser parser = (Parser) recognizer;
    String name = parser.getSourceName();
    TokenStream tokens = parser.getInputStream();

    Token offSymbol = (Token) offendingSymbol;
    int thisError = offSymbol.getTokenIndex();
    if (offSymbol.getType() == -1 && thisError == tokens.size() - 1) {
        Log.debug(this, name + ": Incorrect error: " + msg);
        return;/*from   w w w . jav  a2  s  . c  o  m*/
    }
    String offSymName = JsonLexer.VOCABULARY.getSymbolicName(offSymbol.getType());
    if (thisError > lastError + 10) {
        lastError = thisError - 10;
    }
    for (int idx = lastError + 1; idx <= thisError; idx++) {
        Token token = tokens.get(idx);
        if (token.getChannel() != Token.HIDDEN_CHANNEL)
            Log.error(this, name + ":" + token.toString());
    }
    lastError = thisError;

    List<String> stack = parser.getRuleInvocationStack();
    Collections.reverse(stack);

    Log.error(this, name + " rule stack: " + stack);
    Log.error(this, name + " line " + line + ":" + charPositionInLine + " at " + offSymName + ": " + msg);
}

From source file:org.ballerinalang.composer.service.workspace.rest.datamodel.BallerinaComposerErrorStrategy.java

License:Open Source License

private String getSourceLocation(Parser parser, int line, int position) {
    return parser.getSourceName() + ":" + line + ":" + position + ": ";
}

From source file:org.ballerinalang.langserver.implementation.GotoImplementationCustomErrorStrategy.java

License:Open Source License

@Override
public void reportMatch(Parser recognizer) {
    super.reportMatch(recognizer);

    if (recognizer.getSourceName().equals(relativeSourceFilePath) && !terminateCheck) {
        Token currentToken = recognizer.getCurrentToken();
        // -1 added since the ANTLR line position is not zero based
        int tokenLine = currentToken.getLine() - 1;
        int tokenStartCol = currentToken.getCharPositionInLine();
        int tokenStopCol = tokenStartCol + currentToken.getText().length();

        if (this.line == tokenLine && this.col >= tokenStartCol && this.col <= tokenStopCol) {
            this.lsContext.put(GotoImplementationKeys.SYMBOL_TOKEN_KEY, currentToken.getText());
            this.terminateCheck = true;
        }//ww  w .ja v a  2  s  .co  m
    }
}

From source file:org.fiware.kiara.generator.exceptions.ExceptionErrorStrategy.java

License:Open Source License

@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    String msg = "";
    msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine()
            + ": ";
    msg += "Mismatched input " + getTokenErrorDisplay(e.getOffendingToken());
    msg += " expecting one of " + e.getExpectedTokens().toString(recognizer.getTokenNames()) + "\n";
    msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column "
            + recognizer.getContext().start.getCharPositionInLine() + ";";
    RecognitionException ex = new RecognitionException(msg, recognizer, recognizer.getInputStream(),
            recognizer.getContext());/*from  w  ww  . ja  va 2 s .co  m*/
    ex.initCause(e);
    throw ex;
}

From source file:org.fiware.kiara.generator.exceptions.ExceptionErrorStrategy.java

License:Open Source License

@Override
public void reportMissingToken(Parser recognizer) {
    beginErrorCondition(recognizer);//  w  ww .  jav  a2s.  c o  m
    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "";
    msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine()
            + ": ";
    msg += "Missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t) + ";";
    //msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column " + recognizer.getContext().start.getCharPositionInLine() + ";";
    throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
}