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

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

Introduction

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

Prototype

@Override
    public Interval getSourceInterval() 

Source Link

Usage

From source file:annis.ql.parser.QueryNodeListener.java

License:Apache License

private QueryNode newNode(ParserRuleContext ctx) {
    Long existingID = nodeIntervalToID.get(ctx.getSourceInterval());

    if (existingID == null) {
        throw new IllegalStateException(
                "Could not find a node ID for interval " + ctx.getSourceInterval().toString());
    }/*from w w  w.  j  a v a  2s.co m*/

    QueryNode n = new QueryNode(existingID);
    if (lastVariableDefinition == null) {
        n.setVariable("" + n.getId());
    } else {
        n.setVariable(lastVariableDefinition);
    }
    lastVariableDefinition = null;

    n.setParseLocation(AnnisParserAntlr.getLocation(ctx.getStart(), ctx.getStop()));

    currentAlternative.put(existingID, n);
    localNodes.put(n.getVariable(), n);
    currentTokenPosition.put(ctx.getSourceInterval(), n);

    return n;
}

From source file:ca.nines.ise.dom.DOMBuilder.java

License:Open Source License

/**
 * Set up a newly created node with information from the context.
 *
 * @param n//from ww w . j ava2s.  c  o  m
 * @param ctx
 * @return Node
 */
// @TODO turn this into Node.Builder and provide a Node.builder()
// etc.
private Node setupNode(Node n, ParserRuleContext ctx) {
    Token t = ctx.getStart();
    n.setOwner(dom);
    n.setLine(t.getLine());
    n.setColumn(t.getCharPositionInLine());
    n.setText(tokens.getText(ctx.getSourceInterval()));
    return n;
}

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 {//from  w w  w. ja  va  2 s . 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;
    }
}