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:com.facebook.presto.sql.parser.AstBuilder.java

License:Apache License

private static void check(boolean condition, String message, ParserRuleContext context) {
    if (!condition) {
        throw new ParsingException(message, null, context.getStart().getLine(),
                context.getStart().getCharPositionInLine());
    }/*  ww  w. j a v  a 2s. co  m*/
}

From source file:com.facebook.presto.sql.parser.AstBuilder.java

License:Apache License

public static NodeLocation getLocation(ParserRuleContext parserRuleContext) {
    requireNonNull(parserRuleContext, "parserRuleContext is null");
    return getLocation(parserRuleContext.getStart());
}

From source file:com.github.drrb.rust.netbeans.parsing.RustLexUtils.java

License:Open Source License

public static OffsetRange offsetRangeFor(ParserRuleContext context) {
    return offsetRangeBetween(context.getStart(), context.getStop());
}

From source file:com.metadave.etp.ETPWalker.java

License:Apache License

public ETPTerm processHiddenChannels(ParserRuleContext ctx) {
    Object o = getValue(ctx);//from w  w  w.  j a v  a2  s. c o m
    if (o != null) {
        ETPTerm erlTerm = (ETPTerm) o;

        List<Token> whiteLeft = tokens.getHiddenTokensToLeft(ctx.getStart().getTokenIndex(),
                ETPLexer.WHITESPACE);
        List<Token> whiteRight = tokens.getHiddenTokensToRight(ctx.getStop().getTokenIndex(),
                ETPLexer.WHITESPACE);

        List<Token> commentsLeft = tokens.getHiddenTokensToLeft(ctx.getStart().getTokenIndex(),
                ETPLexer.COMMENTS);
        List<Token> commentsRight = tokens.getHiddenTokensToRight(ctx.getStop().getTokenIndex(),
                ETPLexer.COMMENTS);

        if (whiteLeft != null) {
            StringBuilder b = new StringBuilder();
            for (Token t : whiteLeft) {
                b.append(t.getText());
            }
            //System.out.println("[[" + b.toString() + "[[");
        }

        if (whiteRight != null) {
            StringBuilder b = new StringBuilder();
            for (Token t : whiteRight) {
                b.append(t.getText());
            }
            //System.out.println("]]" + b.toString() + "]]");
        }

        if (commentsLeft != null) {
            StringBuilder b = new StringBuilder();
            for (Token t : commentsLeft) {
                b.append(t.getText());
            }
            //System.out.println("cc" + b.toString() + "cc");
        }

        if (commentsRight != null) {
            StringBuilder b = new StringBuilder();
            for (Token t : commentsRight) {
                b.append(t.getText());
            }
            //System.out.println("CC" + b.toString() + "CC");
        }
        return erlTerm;
    } else {
        return null;
    }

}

From source file:com.microsoft.thrifty.schema.parser.ThriftListener.java

License:Open Source License

private Location locationOf(ParserRuleContext ctx) {
    return locationOf(ctx.getStart());
}

From source file:com.microsoft.thrifty.schema.parser.ThriftListener.java

License:Open Source License

private String formatJavadoc(ParserRuleContext context) {
    List<Token> tokens = new ArrayList<>();
    tokens.addAll(getLeadingComments(context.getStart()));
    tokens.addAll(getTrailingComments(context.getStop()));

    return formatJavadoc(tokens);
}

From source file:com.spotify.heroic.grammar.QueryListener.java

License:Apache License

private static Context context(final ParserRuleContext source) {
    int line = source.getStart().getLine() - 1;
    int col = source.getStart().getStartIndex();
    int lineEnd = source.getStop().getLine() - 1;
    int colEnd = source.getStop().getStopIndex();
    return new Context(line, col, lineEnd, colEnd);
}

From source file:com.sqatntu.metrics.listener.DepthOfConditionNestingListener.java

License:Open Source License

@Override
public void enterStatement(JavaParser.StatementContext ctx) {
    ctx.getChildCount();/*from   ww w .  j  a  v  a 2s.  com*/
    String text = ctx.getStart().getText();
    if (!text.equals("if") && !text.equals("while") && !text.equals("for") && !text.equals("do")) {
        return;
    }

    int depth = 1;
    ParserRuleContext tempContext = ctx.getParent();
    while (!(tempContext instanceof JavaParser.MethodDeclarationContext)) {
        if (tempContext instanceof JavaParser.StatementContext) {
            text = tempContext.getStart().getText();
            if (text.equals("if") || text.equals("while") || text.equals("for") || text.equals("do")) {
                depth++;
            }
        }
        tempContext = tempContext.getParent();
    }
    report.setDepthOfConditionNesting(depth);
}

From source file:com.sqatntu.stylechecker.listener.BraceStyleListener.java

License:Open Source License

private void detectBraceStyle(ParserRuleContext ctx, final int parentLine, final int line) {
    String attribute = null;/*from  ww w.  j  av a  2 s .  c o  m*/
    try {
        attribute = configuration.getAttribute(StyleName.BRACE_STYLE);
    } catch (StyleCheckerException e) {
        // This means that no configuration for method name format is set,
        // so we don't do any check.
        LOG.w(e.getMessage());
        return;
    }
    if (attribute.equals(StyleName.IGNORE_STYLE)) {
        return;
    }

    final int column = ctx.getStart().getCharPositionInLine();
    final String message = "Inconsistent brace style";

    if (attribute.equals(StyleName.BRACE_STYLE_KR) && line != parentLine) {
        String suggestion = "You should move this braces to previous line";
        StyleReportContent reportContent = new StyleReportContent(line, column, message, suggestion);
        report.addReportContents(reportContent);
    } else if (attribute.equals(StyleName.BRACE_STYLE_NON_KR) && line == parentLine) {
        String suggestion = "You should move this braces to next line";
        StyleReportContent reportContent = new StyleReportContent(line, column, message, suggestion);
        report.addReportContents(reportContent);
    }
}

From source file:de.dfki.kiara.idl.KiaraKTDConstructor.java

License:Open Source License

public void perror(ParserRuleContext ctx, String msg) {
    parserErrors.add(fileName + ":" + ctx.getStart().getLine() + ":" + ctx.getStart().getCharPositionInLine()
            + ": " + msg);
}