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

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

Introduction

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

Prototype

public Token getStop() 

Source Link

Document

Get the final token in this context.

Usage

From source file:android.databinding.tool.store.Location.java

License:Apache License

public Location(ParserRuleContext context) {
    this(context == null ? null : context.getStart(), context == null ? null : context.getStop());
}

From source file:annis.ql.parser.JoinListener.java

License:Apache License

private Join addParsedLocation(ParserRuleContext ctx, Join j) {
    j.setParseLocation(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()));
    return j;
}

From source file:annis.ql.parser.QueryNodeListener.java

License:Apache License

private QueryNode newNode(ParserRuleContext ctx) {
    Long existingID = nodeIntervalToID.get(ctx.getSourceInterval());

    if (existingID == null) {
        throw new IllegalStateException(
                "Could not find a node ID for interval " + ctx.getSourceInterval().toString());
    }// www . jav a  2s .  c  o m

    QueryNode n = new QueryNode(existingID);
    if (lastVariableDefinition == null) {
        n.setVariable("" + n.getId());
    } else {
        n.setVariable(lastVariableDefinition);
    }
    lastVariableDefinition = null;

    n.setParseLocation(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()));

    currentAlternative.put(existingID, n);
    localNodes.put(n.getVariable(), n);
    currentTokenPosition.put(ctx.getSourceInterval(), n);

    return n;
}

From source file:codesniffer.java8.adapter.AdapterUtil.java

License:Open Source License

/**
 * If there are no statements within a block, we need a special method to grab any comments that
 * might exist between braces.//from w  ww  .  ja  v a  2  s .  c o  m
 *
 * @param node
 * @param parserRuleContext
 * @param adapterParameters
 */
public static void setInternalComments(Node node, ParserRuleContext parserRuleContext,
        AdapterParameters adapterParameters) {
    BufferedTokenStream tokens = adapterParameters.getTokens();

    if (node == null || parserRuleContext == null || tokens == null) {
        throw new IllegalArgumentException("Parameters must not be null");
    }

    Token startToken = parserRuleContext.getStart();
    Token stopToken = parserRuleContext.getStop();

    List<Token> commentTokens;
    ArrayList<Comment> internalCommentList = new ArrayList<>();

    // Checking to the right of the start token will check inside the statement
    commentTokens = tokens.getHiddenTokensToRight(startToken.getTokenIndex(), Java8Lexer.COMMENTS);
    if (commentTokens != null) {
        internalCommentList.ensureCapacity(commentTokens.size());
        for (Token commentToken : commentTokens) {

            // Skip already claimed comments (prevents comment repeats)
            if (adapterParameters.isCommentTokenClaimed(commentToken.getTokenIndex())) {
                continue;
            } else {
                // Claim it
                adapterParameters.claimCommentToken(commentToken.getTokenIndex());
            }

            if (commentToken.getText().startsWith("/**")) {
                DocumentComment javadocComment = new DocumentComment(commentToken.getText());
                internalCommentList.add(javadocComment);
            } else if (commentToken.getText().startsWith("/*")) {
                BlockComment blockComment = new BlockComment(commentToken.getText());
                internalCommentList.add(blockComment);
            } else if (commentToken.getText().startsWith("//")) {
                LineComment lineComment = new LineComment(commentToken.getText());
                internalCommentList.add(lineComment);
            }
        }
    }
    if (internalCommentList.size() > 0) {
        if (node.getOrphanComments() != null) {
            node.getOrphanComments().addAll(internalCommentList);
        } else {
            node.setOrphanComments(internalCommentList);
        }
    }
    //        if (internalCommentList.size() > 0) {
    //            if (node.getInternalComments() != null) {
    //                node.getInternalComments().addAll(internalCommentList);
    //            } else {
    //                node.setInternalComments(internalCommentList);
    //            }
    //        }
}

From source file:codesniffer.java8.adapter.AdapterUtil.java

License:Open Source License

public static void setPosition(Node node, ParserRuleContext ctx) {
    int beginLine = ctx.getStart().getLine();
    int beginColumn = ctx.getStart().getCharPositionInLine();
    int endLine = ctx.getStop().getLine();
    int endTokenLength = ctx.getStop().getStopIndex() - ctx.getStop().getStartIndex();
    int endColumn = ctx.getStop().getCharPositionInLine() + endTokenLength;

    node.setBeginLine(beginLine);//from  w w  w  . j  av a 2s.c  om
    node.setBeginColumn(beginColumn);
    node.setEndLine(endLine);
    node.setEndColumn(endColumn);
}

From source file:com.bacoder.parser.core.Adapter.java

License:Apache License

protected <T> void setNodeAttributes(T data, ParseTree startNode, ParseTree endNode) {
    if (data instanceof Node) {
        Node node = (Node) data;

        if (startNode instanceof ParserRuleContext) {
            ParserRuleContext context = (ParserRuleContext) startNode;
            node.setStartLine(context.getStart().getLine());
            node.setStartColumn(context.getStart().getCharPositionInLine());
        } else if (startNode instanceof TerminalNode) {
            TerminalNode terminal = (TerminalNode) startNode;
            node.setStartLine(terminal.getSymbol().getLine());
            node.setStartColumn(terminal.getSymbol().getCharPositionInLine());
        }//from ww w .  ja v  a  2s.c o  m

        if (endNode instanceof ParserRuleContext) {
            ParserRuleContext context = (ParserRuleContext) endNode;
            node.setEndLine(context.getStop().getLine());
            node.setEndColumn(
                    context.getStop().getCharPositionInLine() + context.getStop().getText().length() - 1);
        } else if (endNode instanceof TerminalNode) {
            TerminalNode terminal = (TerminalNode) endNode;
            node.setEndLine(terminal.getSymbol().getLine());
            node.setEndColumn(
                    terminal.getSymbol().getCharPositionInLine() + terminal.getSymbol().getText().length() - 1);
        }
    }
}

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);// w  ww  .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 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);
}