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

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

Introduction

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

Prototype

public void setStartIndex(int start) 

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 . ja va 2  s  .co  m
    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: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 {/* ww w .  j  ava 2  s .c  o  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;
}