Example usage for org.antlr.v4.runtime CommonToken setStopIndex

List of usage examples for org.antlr.v4.runtime CommonToken setStopIndex

Introduction

In this page you can find the example usage for org.antlr.v4.runtime CommonToken setStopIndex.

Prototype

public void setStopIndex(int stop) 

Source Link

Usage

From source file:org.eclipse.titan.designer.parsers.ttcn3parser.PPDirectiveTokenFactory.java

License:Open Source License

@Override
public CommonToken create(Pair<TokenSource, CharStream> source, int type, String text, int channel, int start,
        int stop, int line, int charPositionInLine) {
    CommonToken t = new CommonToken(source, type, channel, start, stop);
    t.setLine(line);//w w  w .j a  v  a2  s.com
    t.setStartIndex(start + token.getStartIndex());
    t.setStopIndex(stop + token.getStartIndex() + 1);
    t.setCharPositionInLine(charPositionInLine);
    if (text != null) {
        t.setText(text);
    } else if (copyText && source.b != null) {
        t.setText(source.b.getText(Interval.of(start, stop)));
    }

    return t;
}

From source file:org.sourcepit.ltk.jcomment.AbstractCommentLexer.java

License:Apache License

@Override
public Token nextToken() {
    if (cachedToken != null) {
        Token t = cachedToken;// w w  w  . j a va2  s.  c  om
        cachedToken = null;
        return t;
    }
    Token t = _nextToken();
    CommonToken aggregate = null;
    while (t.getType() == CommentLexer.CommentText) {
        if (aggregate == null) {
            aggregate = (CommonToken) t;
        } else {
            aggregate.setStopIndex(t.getStopIndex());
        }
        t = _nextToken();
    }
    if (aggregate == null) {
        return t;
    }
    cachedToken = t;
    return aggregate;
}

From source file:shadow.typecheck.TypeUpdater.java

License:Apache License

private static Token makeDummyToken(Context node) {
    CommonToken token;

    if (node instanceof ShadowParser.ClassOrInterfaceDeclarationContext)
        token = new CommonToken(
                ((ShadowParser.ClassOrInterfaceDeclarationContext) node).Identifier().getSymbol());
    else if (node instanceof ShadowParser.EnumDeclarationContext)
        token = new CommonToken(((ShadowParser.EnumDeclarationContext) node).Identifier().getSymbol());
    else {/*from w w w .  j  a v a 2s.  co  m*/
        token = new CommonToken(node.getStart());
        //since the token is for a made-up create or property, it has no location in the file
        token.setLine(-1);
        token.setCharPositionInLine(-1);
        token.setStartIndex(0);
        token.setStopIndex(0);
    }

    return token;
}