org.antlr.runtime.IntStream.size()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.antlr.runtime.IntStream.size()方法的一些代码示例,展示了IntStream.size()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IntStream.size()方法的具体详情如下:
包路径:org.antlr.runtime.IntStream
类名称:IntStream
方法名:size

IntStream.size介绍

[英]Only makes sense for streams that buffer everything up probably, but might be useful to display the entire stream or for testing. This value includes a single EOF.
[中]可能只对缓冲所有内容的流有意义,但对显示整个流或测试可能有用。该值包括单个EOF。

代码示例

代码示例来源:origin: net.rapture/Reflex

public static String displayError(IntStream stream, int line, int position, int length) {
  String[] lines = null;
  StringBuilder sb = new StringBuilder();
  if (stream instanceof CharStream) {
    lines = ((CharStream) stream).substring(0, stream.size() - 1).split("\n");
  } else if (stream instanceof TokenStream) {
    lines = ((TokenStream) stream).toString(0, stream.size() - 1).split("\n");
  }
  
  sb.append(" at line ").append(line).append(" while parsing: \n");
  if (lines != null) {
    int start = Math.max(0, line - 5);
    int end = Math.min(lines.length, line + 5);
    int badline = line - 1;
    for (int i = start; i < end; i++) {
      sb.append(String.format("%5d: %s\n", i + 1, lines[i]));
      if (i == badline) {
        for (int j = 0; j < position + 7; j++)
          sb.append("-");
        for (int j = 0; j <= length; j++)
          sb.append("^");
        sb.append("\n");
      }
    }
  }
  return sb.toString();
}

代码示例来源:origin: antlr/antlr3

@Override
public String getText() {
  String badText = null;
  if (start != null) {
    int i = start.getTokenIndex();
    int j = stop.getTokenIndex();
    if (stop.getType() == Token.EOF) {
      j = input.size();
    }
    badText = ((TokenStream)input).toString(i, j);
  } else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

代码示例来源:origin: antlr/antlr3

@Override
public String getText() {
  String badText = null;
  if (start != null) {
    int i = start.getTokenIndex();
    int j = stop.getTokenIndex();
    if (stop.getType() == Token.EOF) {
      j = input.size();
    }
    badText = ((TokenStream)input).toString(i, j);
  } else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

相关文章