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

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

Introduction

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

Prototype

public Token getStart() 

Source Link

Document

Get the initial token in this context.

Usage

From source file:tuprolog.visitor.Visitor4Internal.java

License:Open Source License

/**
 * Create {@link SourceInfoObject} for given context.
 *
 * @param ctx/*from  w w w. j a  va2s.c o  m*/
 *            the {@link DirectiveContext} from the parsed object
 * @return {@link SourceInfoObject}
 */
private SourceInfo getSourceInfo(ParserRuleContext ctx) {
    Token start = ctx.getStart();
    Token stop = ctx.getStop();
    if (stop == null) {
        // happens if we are at EOF...
        stop = start;
    }
    return new SourceInfoObject(this.source.getSource(), start.getLine(), start.getCharPositionInLine(),
            this.source.getStartIndex() + start.getStartIndex() + 1,
            this.source.getStartIndex() + stop.getStopIndex() + 1);
}