當前位置: 首頁>>代碼示例>>Java>>正文


Java Token.getTokenIndex方法代碼示例

本文整理匯總了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);
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:27,代碼來源:InternalHighlightingParser.java

示例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;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:21,代碼來源:SemicolonInjectionHelper.java

示例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;
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:37,代碼來源:SemicolonInjectionHelper.java

示例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;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:14,代碼來源:ParseTree.java

示例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;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:14,代碼來源:ParseTree.java

示例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());
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:11,代碼來源:AbstractInternalAntlrParser.java

示例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();
		}
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:12,代碼來源:AbstractInternalAntlrParser.java

示例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);
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:15,代碼來源:AbstractInternalAntlrParser.java


注:本文中的org.antlr.runtime.Token.getTokenIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。