當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。