当前位置: 首页>>代码示例>>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;未经允许,请勿转载。