当前位置: 首页>>代码示例>>Java>>正文


Java TokenSource.nextToken方法代码示例

本文整理汇总了Java中org.antlr.runtime.TokenSource.nextToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSource.nextToken方法的具体用法?Java TokenSource.nextToken怎么用?Java TokenSource.nextToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.runtime.TokenSource的用法示例。


在下文中一共展示了TokenSource.nextToken方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRepairEntryData

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
/**
 * @since 2.4
 */
@Override
protected RepairEntryData getRepairEntryData(DocumentEvent e) throws Exception {
	int tokenStartsAt = 0;
	int tokenInfoIdx = 0;
	TokenSource source = createTokenSource(e.fDocument.get());
	CommonToken token = (CommonToken) source.nextToken();
	// find start idx
	while (true) {
		if (token == Token.EOF_TOKEN) {
			break;
		}
		if (tokenInfoIdx >= getInternalModifyableTokenInfos().size())
			break;
		TokenInfo tokenInfo = getInternalModifyableTokenInfos().get(tokenInfoIdx);
		if (tokenInfo.getAntlrTokenType() != token.getType()
				|| token.getStopIndex() - token.getStartIndex() + 1 != tokenInfo.getLength())
			break;
		if (tokenStartsAt + tokenInfo.getLength() > e.fOffset)
			break;
		tokenStartsAt += tokenInfo.getLength();
		tokenInfoIdx++;
		token = (CommonToken) source.nextToken();
	}
	return new RepairEntryData(tokenStartsAt, tokenInfoIdx, token, source);
}
 
开发者ID:cplutte,项目名称:bts,代码行数:29,代码来源:BacktrackingLexerDocumentTokenSource.java

示例2: assertTokens

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected void assertTokens(String value, TokenSource tokenSource, String escapedString) {
	if (tokenSource == null)
		return;
	Token token = tokenSource.nextToken();
	if (!escapedString.equals(token.getText())) {
		throw createTokenContentMismatchException(value, escapedString, token);
	}
	
	String rule1 = getRuleName().toUpperCase();
	String rule2 = getRuleName(token);
	// workaround: 
	if ("NAME".equals(rule1) && "ID".equals(rule2)) {
		rule2 = "NAME";
	} else if ("ID".equals(rule1) && "NAME".equals(rule2)) {
		rule1 = "NAME";
	}
	// Ambiguity between NAME and ID rule
	if (!rule1.equals(rule2)) {
		throw createTokenTypeMismatchException(value, escapedString, token);
	}
	String reparsedValue = toValue(token.getText(), null);
	if (value != reparsedValue && !value.equals(reparsedValue)) {
		throw createTokenContentMismatchException(value, escapedString, token);
	}
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:26,代码来源:NAMEValueConverter.java

示例3: isSameTokenSequence

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected boolean isSameTokenSequence(TokenSource originalSource, TokenSource newSource, int expectedLength) {
	Token token = originalSource.nextToken();
	int newLength = 0;
	while(Token.EOF != token.getType()) {
		Token newToken = newSource.nextToken();
		if (token.getType() != newToken.getType()) {
			return false;
		}
		newLength += TokenTool.getLength(newToken);
		token = originalSource.nextToken();
	}
	return newLength == expectedLength;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:TokenSequencePreservingPartialParsingHelper.java

示例4: assertTokens

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected void assertTokens(T value, TokenSource tokenSource, String escapedString) {
	if (tokenSource == null)
		return;
	Token token = tokenSource.nextToken();
	if (!escapedString.equals(token.getText())) {
		throw createTokenContentMismatchException(value, escapedString, token);
	}
	if (!getRuleName().toUpperCase().equals(getRuleName(token))) {
		throw createTokenTypeMismatchException(value, escapedString, token);
	}
	T reparsedValue = toValue(token.getText(), null);
	if (value != reparsedValue && !value.equals(reparsedValue)) {
		throw createTokenContentMismatchException(value, escapedString, token);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:AbstractLexerBasedConverter.java

示例5: equalTokenSequence

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected boolean equalTokenSequence(TokenSource first, TokenSource second) {
	Token token = null;
	while (!(token = first.nextToken()).equals(Token.EOF_TOKEN)) {
		Token otherToken = second.nextToken();
		if (otherToken.equals(Token.EOF_TOKEN)) {
			return false;
		}
		if (!token.getText().equals(otherToken.getText())) {
			return false;
		}
	}
	return true;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:AntlrProposalConflictHelper.java

示例6: equalTokenSequence

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected boolean equalTokenSequence(TokenSource first, TokenSource second) {
	Token token = null;
	while(!(token = first.nextToken()).equals(Token.EOF_TOKEN)) {
		Token otherToken = second.nextToken();
		if (otherToken.equals(Token.EOF_TOKEN)) {
			return false;
		}
		if (!token.getText().equals(otherToken.getText())) {
			return false;
		}
	}
	return true;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:14,代码来源:AntlrProposalConflictHelper.java

示例7: createTokenInfos

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected List<TokenInfo> createTokenInfos(String string) {
	List<TokenInfo> result = Lists.newArrayListWithExpectedSize(string.length() / 3);
	TokenSource source = createTokenSource(string);
	CommonToken token = (CommonToken) source.nextToken();
	while (token != Token.EOF_TOKEN) {
		TokenInfo info = createTokenInfo(token);
		result.add(info);
		token = (CommonToken) source.nextToken();
	}
	return result;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:12,代码来源:DocumentTokenSource.java

示例8: getRepairEntryData

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
/**
 * @since 2.4
 */
protected RepairEntryData getRepairEntryData(DocumentEvent e) throws Exception {
	int tokenStartsAt = 0;
	int tokenInfoIdx = 0;
	for(tokenInfoIdx = 0; tokenInfoIdx< getInternalModifyableTokenInfos().size(); ++tokenInfoIdx) {
		TokenInfo oldToken = getInternalModifyableTokenInfos().get(tokenInfoIdx);
		if(tokenStartsAt <= e.getOffset() && tokenStartsAt + oldToken.getLength() >= e.getOffset())
			break;
		tokenStartsAt += oldToken.getLength();
	}
	final TokenSource delegate = createTokenSource(e.fDocument.get(tokenStartsAt, e.fDocument.getLength() - tokenStartsAt));
	final int offset = tokenStartsAt;
	TokenSource source = new TokenSource() {
		public Token nextToken() {
			CommonToken commonToken = (CommonToken) delegate.nextToken();
			commonToken.setText(commonToken.getText());
			commonToken.setStartIndex(commonToken.getStartIndex()+offset);
			commonToken.setStopIndex(commonToken.getStopIndex()+offset);
			return commonToken;
		}

		public String getSourceName() {
			return delegate.getSourceName();
		}
	};
	final CommonToken token = (CommonToken) source.nextToken();
	return new RepairEntryData(offset, tokenInfoIdx, token, source);
}
 
开发者ID:cplutte,项目名称:bts,代码行数:31,代码来源:DocumentTokenSource.java

示例9: printTokenStream

import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
static void printTokenStream(CommonTokenStream tokens, Map tokenToName) {
    TokenSource source = tokens.getTokenSource();
    Token curr;
    do {
        curr = source.nextToken();
        System.out.println(curr.getText() + " [" + tokenToName.get(String.valueOf(curr.getType())) + "]");
    } while (-1 != curr.getType() ); // eof
}
 
开发者ID:aneveux,项目名称:stack-trace-parser,代码行数:9,代码来源:AntlrUtils.java


注:本文中的org.antlr.runtime.TokenSource.nextToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。