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


Java CommonToken.setStartIndex方法代碼示例

本文整理匯總了Java中org.antlr.runtime.CommonToken.setStartIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java CommonToken.setStartIndex方法的具體用法?Java CommonToken.setStartIndex怎麽用?Java CommonToken.setStartIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.runtime.CommonToken的用法示例。


在下文中一共展示了CommonToken.setStartIndex方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_getTrimmedNodeRange

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
public void test_getTrimmedNodeRange() {
    String source = " hello! ";
    //               012345678
    CommonToken token = new CommonToken(Css3Lexer.IDENT);
    token.setText(source);
    token.setStartIndex(0);
    token.setStopIndex(7); //len - 1 -> points to last char not the end!
    
    Node node = new TokenNode(source, token);
    
    assertEquals(" hello! ", node.image().toString());
    int[] result = NodeUtil.getTrimmedNodeRange(node);

    assertEquals(1, result[0]);
    assertEquals(7, result[1]);
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:NodeUtilTest.java

示例2: createToken

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
 * Create a new token from the given prototype. Any argument besides the prototype is optional and
 * will be ignored if its value is <code>null</code>.
 */
protected CommonToken createToken(CommonToken prototype, String text, 
		Integer charPosInLine, Integer channel, Integer start, Integer stop, Integer type) {
	if (prototype == null)
		throw new IllegalArgumentException("Prototype may not be null.");
	CommonToken result = new CommonToken(prototype);
	if (text != null)
		result.setText(text);
	if (charPosInLine != null)
		result.setCharPositionInLine(charPosInLine.intValue());
	if (channel != null)
		result.setChannel(channel.intValue());
	if (start != null)
		result.setStartIndex(start.intValue());
	if (stop != null)
		result.setStopIndex(stop.intValue());
	if (type != null)
		result.setType(type.intValue());
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:24,代碼來源:AbstractSplittingTokenSource.java

示例3: createEndToken

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
protected Token createEndToken(int offset) {
	CommonToken result = new CommonToken(getEndTokenType());
	result.setText("");
	result.setChannel(Token.DEFAULT_CHANNEL);
	result.setStartIndex(offset);
	result.setStopIndex(offset-1);
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:AbstractIndentationTokenSource.java

示例4: createBeginToken

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
protected Token createBeginToken(int offset) {
	CommonToken result = new CommonToken(getBeginTokenType());
	result.setText("");
	result.setChannel(Token.DEFAULT_CHANNEL);
	result.setStartIndex(offset);
	result.setStopIndex(offset-1);
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:AbstractIndentationTokenSource.java

示例5: testMergeFirstToken

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
@Test public void testMergeFirstToken() {
	CommonToken commonToken = new CommonToken(TOKEN_TYPE, "text");
	commonToken.setStartIndex(4);
	AntlrDatatypeRuleToken token = new AntlrDatatypeRuleToken();
	token.merge(commonToken);
	assertEquals("text", token.getText());
	assertEquals(8, token.getExpectedOffset());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:AntlrDatatypeRuleTokenTest.java

示例6: testMergeSecondToken

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
@Test public void testMergeSecondToken() {
	CommonToken tokenToMerge = new CommonToken(TOKEN_TYPE, "ext");
	tokenToMerge.setStartIndex(6);
	AntlrDatatypeRuleToken token = new AntlrDatatypeRuleToken();
	token.setStartOffset(tokenToMerge.getStartIndex() - 1);
	token.setExpectedOffset(tokenToMerge.getStartIndex());
	token.setText("t");
	token.merge(tokenToMerge);
	assertEquals("text", token.getText());
	assertEquals(9, token.getExpectedOffset());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:12,代碼來源:AntlrDatatypeRuleTokenTest.java

示例7: testMergeSecondTokenUnmatched

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
@Test public void testMergeSecondTokenUnmatched() {
	CommonToken tokenToMerge = new CommonToken(TOKEN_TYPE, "ext");
	tokenToMerge.setStartIndex(6);
	AntlrDatatypeRuleToken token = new AntlrDatatypeRuleToken();
	token.setStartOffset(tokenToMerge.getStartIndex() - 4);
	token.setExpectedOffset(tokenToMerge.getStartIndex() - 3);
	token.setText("t");
	token.merge(tokenToMerge);
	assertEquals("t ext", token.getText());
	assertEquals(9, token.getExpectedOffset());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:12,代碼來源:AntlrDatatypeRuleTokenTest.java


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