Example usage for org.antlr.v4.runtime Token getCharPositionInLine

List of usage examples for org.antlr.v4.runtime Token getCharPositionInLine

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Token getCharPositionInLine.

Prototype

int getCharPositionInLine();

Source Link

Document

The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1

Usage

From source file:org.ballerinalang.langserver.util.references.ReferenceFindTokenErrorStrategy.java

License:Open Source License

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

    if (!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(NodeContextKeys.NODE_NAME_KEY, currentToken.getText());
            this.terminateCheck = true;
        }/*from   w ww  .j a v  a  2 s .c o  m*/
    }
}

From source file:org.ballerinalang.util.parser.BallerinaParserErrorStrategy.java

License:Open Source License

@Override
public void recover(Parser parser, RecognitionException e) {
    Token missingSymbol = parser.getCurrentToken();
    int line = missingSymbol.getLine();
    int position = missingSymbol.getCharPositionInLine();
    String mismatchedToken = getTokenErrorDisplay(missingSymbol);
    String msg = getSourceLocation(parser, line, position) + "invalid token " + mismatchedToken + ". "
            + e.getMessage();//from  w  ww  . j  ava2 s  .co  m
    setContextException(parser);
    throw new ParseCancellationException(msg);
}

From source file:org.beetl.core.AntlrProgramBuilder.java

License:BSD License

public GrammarToken getBTToken(Token t) {
    org.beetl.core.statement.GrammarToken token = new org.beetl.core.statement.GrammarToken(t.getText(),
            t.getLine(), t.getCharPositionInLine());
    return token;
}

From source file:org.btrplace.safeplace.spec.MyCstrSpecVisitor.java

License:Open Source License

private void assertEqualsTypes(Token to, Type expected, Type... got) {
    for (Type t : got) {
        if (!expected.equals(t)) {
            throw SpecException.typeMismatch(filename, to.getCharPositionInLine(), expected, t);
        }//  w  w  w.  j  a v  a 2s .c  o  m
    }
}

From source file:org.btrplace.safeplace.spec.MyCstrSpecVisitor.java

License:Open Source License

private void assertIn(Token to, Term<?> t1, Term<?> t2) {
    Type t = t2.type();/*  w  w  w.  ja  va2  s.c  om*/
    if (!(t instanceof SetType)) {
        throw new SpecException(filename, to.getCharPositionInLine(),
                "The right-hand side must be a collection. Got '" + t2.type() + "'");
    }
    SetType st = (SetType) t;
    if (!st.enclosingType().equals(t1.type())) {
        throw new SpecException(filename, to.getCharPositionInLine(), "Type mismatch. Expected '"
                + st.enclosingType() + "' for left-hand side. Got '" + t1.type() + "'");

    }
}

From source file:org.btrplace.safeplace.spec.SpecException.java

License:Open Source License

public static SpecException unknownSymbol(String name, Token sym) {
    return new SpecException(name, sym.getCharPositionInLine(),
            "Cannot resolve symbol '" + sym.getText() + "'");
}

From source file:org.btrplace.safeplace.spec.SpecException.java

License:Open Source License

public static SpecException unsupportedOperation(String name, Type t1, Token to, Type t2) {
    return new SpecException(name, to.getCharPositionInLine(),
            "Unsupported operation '" + t1 + " " + to.getText() + " " + t2 + "'");
}

From source file:org.btrplace.safeplace.spec.SpecException.java

License:Open Source License

public static SpecException badFunctionCall(String name, Token t, Function f, List<Term> args) {
    String got = args.stream().map(x -> x.type().toString())
            .collect(Collectors.joining(", ", f.id() + "(", ")"));
    return new SpecException(name, t.getCharPositionInLine(),
            "Invalid call. Expected '" + Function.toString(f) + "'. Got '" + got);
}

From source file:org.eclipse.titan.common.parsers.IntervalDetector.java

License:Open Source License

/**
 * Creates and pushes a new interval onto the stack of intervals. This new interval becomes the actual one.
 * <p>/*from   w  w  w .  j  a  va 2  s  .  c o  m*/
 * The ending offset of this interval is not yet set. @see #popInterval(int)
 *
 * @param aToken the first token of the interval
 * @param aType the type of the interval
 */
public final void pushInterval(final Token aToken, final interval_type aType) {
    pushInterval(aToken.getCharPositionInLine(), aToken.getLine(), aType);
}

From source file:org.eclipse.titan.common.parsers.IntervalDetector.java

License:Open Source License

/**
 * Pops the actual interval off of the stack, making its parent the actual interval. The ending offset of the popped off interval is set here.
 * <p>/*w w w  . j a  va2  s .  c  om*/
 * If the actual interval is the root interval, than it is not popped off the stack. This situation can only happen in case of a syntactically
 * invalid file.
 *
 * @param aToken the last token of the interval
 */
public final void popInterval(final Token aToken) {
    popInterval(aToken.getCharPositionInLine(), aToken.getLine());
}