本文整理汇总了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;
}