当前位置: 首页>>代码示例>>Java>>正文


Java Lexer.EOF属性代码示例

本文整理汇总了Java中org.antlr.v4.runtime.Lexer.EOF属性的典型用法代码示例。如果您正苦于以下问题:Java Lexer.EOF属性的具体用法?Java Lexer.EOF怎么用?Java Lexer.EOF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.antlr.v4.runtime.Lexer的用法示例。


在下文中一共展示了Lexer.EOF属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dentedToBraced

public static String dentedToBraced(Lexer lexer, int indent, int dedent, int nl, String nlReplacement) {
  StringBuilder sb = new StringBuilder();
  int indentation = 0;
  int charsWrittenInLine = 0;
  for (Token t = lexer.nextToken(); t.getType() != Lexer.EOF; t = lexer.nextToken()) {
    int expectCharsWritten = t.getCharPositionInLine();
    int tokenType = t.getType();
    if (tokenType == indent) {
      sb.append(INDENT_BRACE).append('\n');
      ++indentation;
      charsWrittenInLine = 0;
    } else if (tokenType == dedent) {
      --indentation;
      addSpaces(sb, indentation * 2);
      sb.append(DEDENT_BRACE).append('\n');
      charsWrittenInLine = 0;
    } else if (tokenType == nl) {
      sb.append(nlReplacement);
      charsWrittenInLine = 0;
    } else {
      String text = t.getText();
      if (charsWrittenInLine < expectCharsWritten) {
        if ("else".equals(text)) {
          // Instead of a newline (which we previously added), just add a space. Also, note that the
          // charsWrittenInLine happens unconditionally. This is intentional, to trick the indent-inserter into
          // thinking it's already done its job. The net effect is to put else's on the same line as the if's
          // closing brace, which is a standard style.
          chomp(sb, '\n');
          sb.append(' ');
        } else {
          addSpaces(sb, expectCharsWritten - charsWrittenInLine);
        }
        charsWrittenInLine = expectCharsWritten;
      }
      sb.append(text);
      charsWrittenInLine += text.length();
    }
  }
  return sb.toString();
}
 
开发者ID:yshavit,项目名称:antlr-denter,代码行数:40,代码来源:GrammarForker.java

示例2: runLexer

private <L extends Lexer> int runLexer(Class<L> lexerClass, String source, long runs,
                                       Function<? super L, Tokens> lexerToIter) {
  QuickRandom r = new QuickRandom();
  for (long i = 0; i < runs; ++i) {
    L lexer = ParserUtils.getLexer(lexerClass, source);
    Tokens iter = lexerToIter.apply(lexer);
    for (Token t = iter.nextToken(); t.getType() != Lexer.EOF; t = iter.nextToken()) {
      r.next();
    }
  }
  return r.next();
}
 
开发者ID:yshavit,项目名称:antlr-denter,代码行数:12,代码来源:BenchGramBenchmark.java

示例3: countTokens

private int countTokens(Class<? extends Lexer> lexerClass, String source) {
  Lexer lexer = ParserUtils.getLexer(lexerClass, source);
  int count = 0;
  for (Token t = lexer.nextToken(); t.getType() != Lexer.EOF; t = lexer.nextToken()) {
    ++count;
  }
  return count;
}
 
开发者ID:yshavit,项目名称:antlr-denter,代码行数:8,代码来源:BenchGramBenchmark.java


注:本文中的org.antlr.v4.runtime.Lexer.EOF属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。