Example usage for org.antlr.v4.runtime ParserRuleContext getStart

List of usage examples for org.antlr.v4.runtime ParserRuleContext getStart

Introduction

In this page you can find the example usage for org.antlr.v4.runtime ParserRuleContext getStart.

Prototype

public Token getStart() 

Source Link

Document

Get the initial token in this context.

Usage

From source file:net.maritimecloud.internal.msdl.parser.SourceTagHolder.java

License:Apache License

SourceTagHolder(ParsedMsdlFile file, ParserRuleContext c) {
    this.file = requireNonNull(file);
    this.startLine = c.getStart().getLine();
    this.startCharPosition = c.getStart().getCharPositionInLine();
    this.stopLine = c.getStop().getLine();
    this.stopCharPosition = c.getStop().getCharPositionInLine();
}

From source file:nl.lxtreme.libtdl.grammar.adv.AdvTdlSemanticAnalyzer.java

License:Apache License

private boolean validateRange(ParserRuleContext lower, ParserRuleContext upper, String msg) {
    Long lowerBound = decode(lower.getText());
    Long upperBound = decode(upper.getText());

    boolean valid = (lowerBound != null) && (upperBound != null) && (lowerBound.compareTo(upperBound) < 0);

    if (!valid) {
        int offset = lower.getStart().getStartIndex();
        int length = lower.getStop().getStopIndex() - offset;

        MarkerBuilder builder = new MarkerBuilder();
        Marker marker = builder/*from   www  .j  a  v  a 2 s.  c o  m*/
                .setCategory(Category.SEMANTIC).setType(Type.ERROR).setLocation(offset, length,
                        lower.getStart().getLine(), lower.getStart().getCharPositionInLine())
                .setDescription(msg).build();

        m_problemReporter.report(marker);
    }

    return valid;
}

From source file:nl.lxtreme.libtdl.grammar.Util.java

License:Apache License

/**
 * Validates whether a given context denotes a numeric value in the given
 * range. In case the value falls outside the defined range, a problem will
 * be added to the given problem reporter.
 * /*w  w w .  j  a v  a2  s .  c o  m*/
 * @param ctx
 *            the parser context that denotes the numeric value to test;
 * @param lower
 *            the lower bound (inclusive!) of the range that is valid;
 * @param upper
 *            the upper bound (inclusive!) of the range that is valid;
 * @param msg
 *            the message to add as problem marker in case the value is
 *            invalid;
 * @param reporter
 *            the problem reporter to add the marker to.
 * @return the parsed numeric value of the given parser context, or
 *         <code>null</code> in case it did not denote a valid numeric
 *         value (not inside the given range, or otherwise invalid).
 */
public static Long validateValue(ParserRuleContext ctx, long lower, long upper, String msg,
        ProblemReporter reporter) {
    String text = null;
    if (ctx != null) {
        text = ctx.getText();
    }
    Long value = decode(text);
    if (value == null) {
        return null;
    }

    if (!inRange(value.longValue(), lower, upper)) {
        int offset = ctx.getStart().getStartIndex();
        int length = ctx.getStop().getStopIndex() - offset;

        MarkerBuilder builder = new MarkerBuilder();
        Marker marker = builder.setCategory(Category.SEMANTIC).setType(Type.ERROR)
                .setLocation(offset, length, ctx.getStart().getLine(), ctx.getStart().getCharPositionInLine())
                .setDescription(msg).build();

        reporter.report(marker);
        return null;
    }

    return value;
}

From source file:no.ssb.vtl.script.error.VTLScriptException.java

License:Apache License

private void extractPositionFromContext(ParserRuleContext ctx) {
    checkNotNull(ctx);// ww  w  .  j  a  va 2 s.  c  o  m
    startLine = ctx.getStart().getLine();
    startColumn = ctx.getStart().getCharPositionInLine();
    if (ctx.getStop() != null) {
        stopLine = ctx.getStop().getLine();
        if (ctx.getStart() == ctx.getStop()) {
            Token token = ctx.getStart();
            stopColumn = startColumn + token.getText().length();
        } else {
            stopColumn = ctx.getStop().getCharPositionInLine();
        }
    }
}

From source file:oracle.kv.impl.query.compiler.Translator.java

License:Open Source License

private static QueryException.Location getLocation(ParserRuleContext ctx) {
    int startLine = -1;
    int startColumn = -1;
    int endLine = -1;
    int endColumn = -1;

    if (ctx != null && ctx.getStart() != null) {
        startLine = ctx.getStart().getLine();
        startColumn = ctx.getStart().getCharPositionInLine();
    }//from w  w w .  j  av  a  2 s.c  o m

    if (ctx != null && ctx.getStop() != null) {
        endLine = ctx.getStop().getLine();
        endColumn = ctx.getStop().getCharPositionInLine();
    }

    return new QueryException.Location(startLine, startColumn, endLine, endColumn);
}

From source file:org.apache.hive.hplsql.Exec.java

License:Apache License

/**
 * Trace information//from w ww  .  j  a  v  a 2s  .  com
 */
public void trace(ParserRuleContext ctx, String message) {
    if (!trace) {
        return;
    }
    if (ctx != null) {
        System.out.println("Ln:" + ctx.getStart().getLine() + " " + message);
    } else {
        System.out.println(message);
    }
}

From source file:org.apache.hive.hplsql.Exec.java

License:Apache License

/**
 * Informational messages/*from   w  w w. j a  va 2s.co m*/
 */
public void info(ParserRuleContext ctx, String message) {
    if (!info) {
        return;
    }
    if (ctx != null) {
        System.err.println("Ln:" + ctx.getStart().getLine() + " " + message);
    } else {
        System.err.println(message);
    }
}

From source file:org.apache.hive.hplsql.Exec.java

License:Apache License

/**
 * Error message// ww  w  . j av a 2s .  c o m
 */
public void error(ParserRuleContext ctx, String message) {
    if (ctx != null) {
        System.err.println("Ln:" + ctx.getStart().getLine() + " " + message);
    } else {
        System.err.println(message);
    }
}

From source file:org.apache.sysml.parser.common.CommonSyntacticValidator.java

License:Apache License

protected void constDoubleIdExpressionHelper(ParserRuleContext ctx, ExpressionInfo me) {
    try {/*w w  w .  java  2  s  .c o m*/
        double val = Double.parseDouble(ctx.getText());
        me.expr = new DoubleIdentifier(ctx, val, currentFile);
    } catch (Exception e) {
        notifyErrorListeners("cannot parse the float value: \'" + ctx.getText() + "\'", ctx.getStart());
        return;
    }
}

From source file:org.apache.sysml.parser.common.CommonSyntacticValidator.java

License:Apache License

protected void constIntIdExpressionHelper(ParserRuleContext ctx, ExpressionInfo me) {
    try {/*  w w w .j ava 2 s .c om*/
        long val = Long.parseLong(ctx.getText());
        me.expr = new IntIdentifier(ctx, val, currentFile);
    } catch (Exception e) {
        notifyErrorListeners("cannot parse the int value: \'" + ctx.getText() + "\'", ctx.getStart());
        return;
    }
}