private String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (ruleNames != null) {
if (t instanceof RuleNode) {
int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
String ruleName = ruleNames.get(ruleIndex);
return ruleName;
}
else if (t instanceof ErrorNode) {
return "<" + t.toString() + ">";
}
else if (t instanceof TerminalNode) {
Token symbol = ((TerminalNode) t).getSymbol();
if (symbol != null) {
String s = symbol.getText();
return "'" + s + "'";
}
}
}
// no recog for rule names
Object payload = t.getPayload();
if (payload instanceof Token) {
return ((Token) payload).getText();
}
return t.getPayload().toString();
}
ParseTreeCommand.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:antlr4ide
作者:
评论列表
文章目录