ParseTreeCommand.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:antlr4ide 作者:
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();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号