本文整理匯總了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();
}
示例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();
}
示例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;
}