Example usage for org.antlr.v4.runtime.tree RuleNode getSourceInterval

List of usage examples for org.antlr.v4.runtime.tree RuleNode getSourceInterval

Introduction

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

Prototype

Interval getSourceInterval();

Source Link

Document

Return an Interval indicating the index in the TokenStream of the first and last token associated with this subtree.

Usage

From source file:net.klazz.symboliclua.conv.Converter.java

License:Open Source License

private List<String> whitespaces(RuleNode node) {
    List<String> ret = new ArrayList<>();
    Interval interval = node.getSourceInterval();
    int a = node.getParent() == null ? 0 : interval.a;
    int b = node.getParent() == null ? mStream.size() - 1 : interval.b;
    for (int i = 0; i < node.getChildCount(); i++) {
        ParseTree c = node.getChild(i);//from  w  w w.  jav a  2 s  .c  om
        Interval v = c.getSourceInterval();
        ret.add(a < v.a ? mStream.getText(new Interval(a, v.a - 1)) : "");
        a = v.b + 1;
    }
    ret.add(a <= b ? mStream.getText(new Interval(a, b)) : "");
    return ret;
}