Example usage for org.antlr.v4.runtime BufferedTokenStream getText

List of usage examples for org.antlr.v4.runtime BufferedTokenStream getText

Introduction

In this page you can find the example usage for org.antlr.v4.runtime BufferedTokenStream getText.

Prototype

@Override
    public String getText(RuleContext ctx) 

Source Link

Usage

From source file:org.pshdl.model.parser.SourceInfo.java

License:Open Source License

public SourceInfo(BufferedTokenStream tokens, ParserRuleContext context) {
    this.context = context;
    this.startLine = context.start.getLine();
    this.totalOffset = context.start.getStartIndex();
    this.startPosInLine = context.start.getCharPositionInLine();
    if (context.stop != null) {
        this.endLine = context.stop.getLine();
        this.endPosInLine = context.stop.getCharPositionInLine();
    } else {//w ww. ja va 2s  .  c  o  m
        this.endLine = startLine;
        this.endPosInLine = startPosInLine;
    }
    if (tokens != null) {
        this.length = tokens.getText(context.getSourceInterval()).length();
        final List<Token> hidden = tokens.getHiddenTokensToLeft(context.start.getTokenIndex(),
                PSHDLLangLexer.COMMENTS);
        if (hidden != null) {
            for (final Token token : hidden) {
                comments.add(token.getText());
            }
        }
    } else {
        this.length = -1;
    }
}