本文整理汇总了Java中org.antlr.v4.runtime.tree.ParseTree.getSourceInterval方法的典型用法代码示例。如果您正苦于以下问题:Java ParseTree.getSourceInterval方法的具体用法?Java ParseTree.getSourceInterval怎么用?Java ParseTree.getSourceInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.tree.ParseTree
的用法示例。
在下文中一共展示了ParseTree.getSourceInterval方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
public static void print(final ParseTree node, final int level, CommonTokenStream stream) {
final Interval sourceInterval = node.getSourceInterval();
final Token firstToken = stream.get(sourceInterval.a);
int line = firstToken.getLine();
int charStart = firstToken.getCharPositionInLine();
int endLine = line;
int endChar = charStart + firstToken.getText().length();
String data = "@(" + line + ":" + charStart + "," + endLine + ":" + endChar + ") with text: "
+ firstToken.getText();
final int tmp = level + 1;
final StringBuilder sb = new StringBuilder();
sb.append(StringUtils.repeat("\t", level));
sb.append(node.getClass().getSimpleName() + ": " + data + " :" + node.getText());
System.out.println(sb.toString());
final int n = node.getChildCount();
for (int i = 0; i < n; i++) {
final ParseTree c = node.getChild(i);
print(c, tmp, stream);
}
}