本文整理汇总了Java中org.antlr.runtime.Token.getTokenIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Token.getTokenIndex方法的具体用法?Java Token.getTokenIndex怎么用?Java Token.getTokenIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.Token
的用法示例。
在下文中一共展示了Token.getTokenIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: announce
import org.antlr.runtime.Token; //导入方法依赖的package包/类
@Override
protected void announce(Token start, Token stop, AbstractElement element) {
if (start != null && start != Token.EOF_TOKEN) {
if (start == stop) {
announce(start, element);
} else {
CommonToken castedStart = (CommonToken) start;
if (stop == null) { // possible error condition
if (start.getTokenIndex() == state.lastErrorIndex) {
return;
}
}
CommonToken castedEnd = (CommonToken) stop;
Integer newType = rewriter.rewrite(castedStart, element);
if (newType != null && castedEnd != null && castedEnd != Token.EOF_TOKEN) {
LazyTokenStream castedInput = (LazyTokenStream) this.input;
for (int i = castedStart.getTokenIndex() + 1; i < castedEnd.getTokenIndex(); i++) {
Token token = castedInput.get(i);
if (token.getChannel() != Token.HIDDEN_CHANNEL)
token.setType(newType);
}
castedEnd.setType(newType);
}
}
}
}
示例2: hasDisallowedEOL
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/**
* Returns true if there was an unexpected EOL.
*/
public static boolean hasDisallowedEOL(Callback callback) {
TokenStream input = callback.getInput();
Token lt = input.LT(1);
// Start on the position before the current token and scan backwards off channel tokens until the previous on
// channel token.
for (int ix = lt.getTokenIndex() - 1; ix > 0; ix--) {
lt = input.get(ix);
if (lt.getChannel() == Token.DEFAULT_CHANNEL) {
// On channel token found: stop scanning.
break;
} else if (isSemicolonEquivalent(lt)) {
return true;
}
}
return false;
}
示例3: promoteEOL
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/**
* <p>
* Promotes EOL which may lead to an automatically inserted semicolon. This is probably the most important method
* for automatic semicolon insertion, as it is only possible to insert a semicolon in case of line breaks (even if
* they are hidden in a multi-line comment!).
* </p>
*/
public static void promoteEOL(Callback callback) {
RecognizerSharedState state = callback.getState();
TokenStream input = callback.getInput();
// Don't promote EOL if there was a syntax error at EOF
if (state.lastErrorIndex == input.size()) {
return;
}
// Get current token and its type (the possibly offending token).
Token prev = input.LT(-1);
Token next = input.LT(1);
int la = next.getType();
// Promoting an EOL means switching it from off channel to on channel.
// A ML_COMMENT gets promoted when it contains an EOL.
for (int idx = prev == null ? 0 : prev.getTokenIndex() + 1, max = la == Token.EOF ? input.size()
: next.getTokenIndex(); idx < max; idx++) {
Token lt = input.get(idx);
if (lt.getChannel() == Token.DEFAULT_CHANNEL) {
// On channel token found: stop scanning (previously promoted)
break;
} else if (isSemicolonEquivalent(lt)) {
// We found our EOL: promote the token to on channel, position the input on it and reset the rule
// start.
lt.setChannel(Token.DEFAULT_CHANNEL);
input.seek(idx);
break;
}
}
}
示例4: getMin
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/** Returns the token that comes first in the input stream. */
private Token getMin(Token one, Token two) {
if (one.getTokenIndex() < 0) {
return two;
}
if (two.getTokenIndex() < 0) {
return one;
}
if (one.getTokenIndex() < two.getTokenIndex()) {
return one;
}
return two;
}
示例5: getMax
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/** Returns the token that comes last in the input stream. */
private Token getMax(Token one, Token two) {
if (one.getTokenIndex() < 0) {
return two;
}
if (two.getTokenIndex() < 0) {
return one;
}
if (one.getTokenIndex() > two.getTokenIndex()) {
return one;
}
return two;
}
示例6: appendAllTokens
import org.antlr.runtime.Token; //导入方法依赖的package包/类
protected void appendAllTokens() {
for (int x = lastConsumedIndex + 1; input.size() > x; input.consume(), x++) {
Token hidden = input.get(x);
createLeafNode(hidden, null);
lastConsumedIndex = hidden.getTokenIndex();
}
if (currentError != null) {
appendError(getLastLeafNode());
}
}
示例7: appendTrailingHiddenTokens
import org.antlr.runtime.Token; //导入方法依赖的package包/类
protected void appendTrailingHiddenTokens() {
Token tokenBefore = input.LT(-1);
int size = input.size();
if (tokenBefore != null && tokenBefore.getTokenIndex() < size) {
for (int x = tokenBefore.getTokenIndex() + 1; x < size; x++) {
Token hidden = input.get(x);
createLeafNode(hidden, null);
lastConsumedIndex = hidden.getTokenIndex();
}
}
}
示例8: newLeafNode
import org.antlr.runtime.Token; //导入方法依赖的package包/类
protected void newLeafNode(Token token, EObject grammarElement) {
if (token == null)
return;
final int tokenIndex = token.getTokenIndex();
if (tokenIndex > lastConsumedIndex) {
for (int x = lastConsumedIndex + 1; x < tokenIndex; x++) {
Token hidden = input.get(x);
createLeafNode(hidden, null);
}
lastConsumedIndex = tokenIndex;
lastConsumedNode = createLeafNode(token, grammarElement);
}
}