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

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

Introduction

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

Prototype

int getLine();

Source Link

Document

The line number on which the 1st character of this token was matched, line=1..n

Usage

From source file:de.huberlin.wbi.cuneiform.core.preprocess.PreListener.java

License:Apache License

@Override
public void exitFromStackExpr(@NotNull CuneiformParser.FromStackExprContext ctx) {

    Token symbol;

    symbol = ctx.FROMSTACK().getSymbol();

    if (exprStack.isEmpty())
        throw new ParseException(symbol.getLine(), symbol.getCharPositionInLine(), symbol.getText(),
                "Pipe destination encountered where there is no source.");

    rewriter.replace(symbol, exprStack.pop());
}

From source file:de.uni.bremen.monty.moco.ast.ASTBuilder.java

License:Open Source License

private Position position(Token idSymbol) {
    return new Position(fileName, idSymbol.getLine(), idSymbol.getCharPositionInLine());
}

From source file:de.up.ling.irtg.codec.ExceptionErrorStrategy.java

private String getTokenPosition(Token t) {
    return "Line " + t.getLine() + ":" + t.getCharPositionInLine();
}

From source file:edu.clemson.cs.r2jt.absynnew.UnderliningErrorListener.java

License:Open Source License

/**
 * <p>This is called mainly when an {@link SrcErrorException} is raised
 * or caught.</p>// w  ww .  j a v  a2 s.  com
 *
 * @param offendingSymbol The token indicating a problem site.
 * @param msg The error message.
 */
public void semanticError(Token offendingSymbol, String msg) {
    if (offendingSymbol == null) {
        System.err.println("-1:-1:-1: " + msg);
    } else if (offendingSymbol.getTokenSource() == null) {
        System.err.println("-1:-1:-1: " + msg);
    } else {
        String fileName = offendingSymbol.getTokenSource().getSourceName();
        System.err.println(groomFileName(fileName) + ":" + offendingSymbol.getLine() + ":"
                + offendingSymbol.getCharPositionInLine() + ": " + msg);

        underlineError(null, offendingSymbol, offendingSymbol.getLine(),
                offendingSymbol.getCharPositionInLine());
    }
}

From source file:edu.clemson.cs.rsrg.parsing.TreeBuildingListener.java

License:Open Source License

/**
 * <p>Create a location for the current parser token
 * we are visiting.</p>//  w  w w . j a  v a 2 s .c om
 *
 * @param t The visiting ANTLR4 parser token.
 *
 * @return A {@link Location} for the rule.
 */
private Location createLocation(Token t) {
    return new Location(myFile, t.getLine(), t.getCharPositionInLine());
}

From source file:edu.clemson.resolve.compiler.LanguageSemanticsMessage.java

License:BSD License

public LanguageSemanticsMessage(ErrorKind etype, Token offendingToken, Object... args) {
    super(etype, offendingToken, args);
    if (offendingToken != null) {
        this.fileName = Utils.groomFileName(offendingToken.getTokenSource().getSourceName());
        this.line = offendingToken.getLine();
        this.charPosition = offendingToken.getCharPositionInLine();
    }/*from  w w  w  . java  2s .c om*/
}

From source file:edu.clemson.resolve.compiler.LanguageSyntaxMessage.java

License:BSD License

public LanguageSyntaxMessage(ErrorKind etype, Token offendingToken, RecognitionException antlrException,
        Object... args) {/*from   w  w w  .j a  v a 2 s. co  m*/
    super(etype, antlrException, offendingToken, args);
    this.offendingToken = offendingToken;
    if (offendingToken != null) {
        this.fileName = offendingToken.getTokenSource().getSourceName();
        this.line = offendingToken.getLine();
        this.charPosition = offendingToken.getCharPositionInLine();
    }
}

From source file:info.fulloo.trygve.error.ErrorLogger.java

License:Open Source License

public static void error(final ErrorIncidenceType errorType, final Token token, final String s1,
        final String s2, final String s3, final String s4) {
    System.err.print("line ");
    System.err.print(null == token ? 0 : token.getLine());
    System.err.print(": ");
    ErrorLogger.error(errorType, s1, s2, s3, s4);
}

From source file:info.fulloo.trygve.error.ErrorLogger.java

License:Open Source License

public static void error(final ErrorIncidenceType errorType, final Token token, final String s1,
        final String s2, final String s3, final String s4, final String s5, final String s6) {
    updateCounts(errorType);/*from  w ww  .j  a  va 2s.  co  m*/
    System.err.print("line ");
    System.err.print(null == token ? 0 : token.getLine());
    System.err.print(": ");
    System.err.print(s1);
    System.err.print(s2);
    System.err.print(s3);
    System.err.print(s4);
    System.err.print(s5);
    System.err.print(s6);
    System.err.println();
}

From source file:info.fulloo.trygve.parser.Pass1Listener.java

License:Open Source License

private ExpressionStackAPI exprFromExprDotJAVA_ID(final TerminalNode ctxJAVA_ID, final Token ctxGetStart,
        final TerminalNode ctxABELIAN_INCREMENT_OP) {
    // Certified Pass 1 version ;-) There is no longer any Pass 2+ version
    UnaryopExpressionWithSideEffect.PreOrPost preOrPost;
    Type type = null;/*from  w w w.  j ava 2 s  .c  o m*/
    final ExpressionStackAPI qualifier = parsingData_.popRawExpression();
    Expression expression = null;
    final String javaIdString = ctxJAVA_ID.getText();
    preOrPost = UnaryopExpressionWithSideEffect.PreOrPost.Post;

    if (null != ctxABELIAN_INCREMENT_OP) {
        final Interval JavaIDInterval = ctxJAVA_ID.getSourceInterval();
        final Interval OperatorInterval = ctxABELIAN_INCREMENT_OP.getSourceInterval();
        preOrPost = JavaIDInterval.startsAfter(OperatorInterval) ? UnaryopExpressionWithSideEffect.PreOrPost.Pre
                : UnaryopExpressionWithSideEffect.PreOrPost.Post;
    }

    assert null != qualifier;
    if (null != qualifier.type() && qualifier.type().name().equals("Class")) {
        // This is where we handle types like "System" for System.out.print*
        // Now we need to get the actual class of that name
        final Type rawClass = currentScope_.lookupTypeDeclarationRecursive(qualifier.name());
        assert rawClass instanceof ClassType;
        final ClassType theClass = (ClassType) rawClass;

        final ObjectDeclaration odecl = theClass.type().enclosedScope().lookupObjectDeclaration(javaIdString);
        if (null != odecl) {
            // It must be static
            final ObjectDeclaration odecl2 = theClass.type().enclosedScope()
                    .lookupStaticDeclaration(javaIdString);
            if (null == odecl2) {
                errorHook5p2(ErrorIncidenceType.Fatal, ctxGetStart.getLine(),
                        "Attempt to access instance member `", javaIdString,
                        "' as a member of class `" + theClass.name(), "'.");
                type = new ErrorType();
            } else {
                type = odecl.type();
            }
            assert type != null;

            if (null != ctxABELIAN_INCREMENT_OP) {
                expression = new QualifiedClassMemberExpressionUnaryOp(theClass, javaIdString, type,
                        ctxABELIAN_INCREMENT_OP.getText(), preOrPost);
            } else {
                expression = new QualifiedClassMemberExpression(theClass, javaIdString, type);
            }
        } else {
            errorHook5p2(ErrorIncidenceType.Fatal, ctxGetStart.getLine(), "Member `", javaIdString,
                    "' of `" + qualifier.name(), "' is not defined.");
            expression = new ErrorExpression(null);
        }
    } else {
        final Expression object = (Expression) qualifier;
        object.setResultIsConsumed(true);
        final Type objectType = object.type();
        Declaration odecl = null;
        if (objectType.isntError()) {
            odecl = objectType.enclosedScope().lookupObjectDeclarationRecursive(javaIdString);
        }

        if (null != odecl) {
            type = odecl.type();
            assert type != null;

            if (null != ctxABELIAN_INCREMENT_OP) {
                expression = new QualifiedIdentifierExpressionUnaryOp(object, javaIdString, type,
                        ctxABELIAN_INCREMENT_OP.getText(), preOrPost);
            } else {
                expression = new QualifiedIdentifierExpression(object, javaIdString, type);
            }

            if (odecl instanceof ObjectDeclaration) {
                final ObjectDeclaration odeclAsOdecl = (ObjectDeclaration) odecl;
                final boolean isAccessible = currentScope_.canAccessDeclarationWithAccessibility(odeclAsOdecl,
                        odeclAsOdecl.accessQualifier_, ctxGetStart.getLine());
                if (isAccessible == false) {
                    errorHook6p2(ErrorIncidenceType.Fatal, ctxGetStart.getLine(), "Cannot access expression `",
                            expression.getText(), "' with `", odeclAsOdecl.accessQualifier_.asString(),
                            "' access qualifier.", "");
                }
            } else if (odecl.isntError()) {
                errorHook5p2(ErrorIncidenceType.Fatal, ctxGetStart.getLine(), "Cannot access expression `",
                        expression.getText(), "' with non-object type declaration", "");
            }
        } else if (null == (expression = degenerateProcedureCheck(qualifier, objectType, javaIdString,
                ctxGetStart.getLine()))) {
            if (object.isntError() && object.type().isntError()) {
                errorHook5p2(ErrorIncidenceType.Fatal, ctxGetStart.getLine(), "Field `", javaIdString,
                        "' not found as member of `", object.type().name() + "'.");
            }
            type = new ErrorType();
            odecl = new ErrorDeclaration("");
            expression = new ErrorExpression(null);
        }
    }

    return null == expression ? new ErrorExpression(null) : expression;
}