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

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

Introduction

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

Prototype

@Override
    public void setCharPositionInLine(int charPositionInLine) 

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);//from w  w w.j  a v  a  2  s .  c om
    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 {//from   w w  w.java2s .c  om
        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;
}