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


Java CommonToken.getType方法代碼示例

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


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

示例1: shouldSkipASI

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
 * Returns true if the ASI at the end should be skipped for a second pass of the CA parser. Otherwise false.
 */
private boolean shouldSkipASI(CommonToken lastToken) {
	if (lastToken.getType() == eol) {
		return true;
	}
	if (lastToken.getType() == semi && lastToken.getText() != null && !";".equals(lastToken.getText())) {
		return true;
	}
	return false;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:13,代碼來源:CustomN4JSParser.java

示例2: createTokenInfo

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
 * JSDoc comments are identified by the lexer as normal ML comments to simplify the ASI code. If a comment starts
 * with the sequence @çode{/**} it is remapped to a JS Doc token.
 */
@Override
protected TokenInfo createTokenInfo(CommonToken token) {
	if (token.getType() == InternalN4JSParser.RULE_ML_COMMENT) {
		String text = token.getText();
		if (text.length() > 4 && text.startsWith("/**") && text.charAt(3) != '*') {
			CommonToken jsDoc = new CommonToken(token);
			jsDoc.setType(JS_DOC_TOKEN);
			return super.createTokenInfo(jsDoc);
		}
	}
	return super.createTokenInfo(token);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:17,代碼來源:ParserBasedDocumentTokenSource.java

示例3: dumpTokens

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
public static void dumpTokens(Css3Lexer lexer) {
    System.out.println("Tokens:");
    CommonToken t;
    while ((t = (CommonToken)lexer.nextToken()) != null) {
        System.out.println(
                t.getStartIndex() + "-" + t.getStopIndex() 
                + ": " + t.getText() + "(" + (t.getType() == -1 ? "" : Css3Parser.tokenNames[t.getType()]) + ")");
        
        if(t.getType() == Css3Lexer.EOF) {
            break;
        }
    }
    System.out.println("-------------");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:TestUtil.java

示例4: testSlCommentEOF

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
 * see BUG 234135: Comments on EOF not detected
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=234135
 */
@Test public void testSlCommentEOF() {
	String model = "a\n//sl comment";
	InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
	lexer.setCharStream(new ANTLRStringStream(model));
	CommonTokenStream stream = new CommonTokenStream(lexer);
	Object eofLineComment = stream.getTokens().get(2);
	assertTrue(eofLineComment instanceof CommonToken);
	CommonToken commonToken = (CommonToken) eofLineComment;
	int type = commonToken.getType();
	assertEquals(InternalSimpleExpressionsTestLanguageLexer.RULE_SL_COMMENT, type);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:16,代碼來源:LexerSLComment.java

示例5: instantiate

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
  CommonToken ct = (CommonToken)oldInstance;
  Object[] args = {ct.getType(), ct.getText()};
  return new Expression(ct, ct.getClass(), "new", args);
}
 
開發者ID:mini666,項目名稱:hive-phoenix-handler,代碼行數:7,代碼來源:Utilities.java

示例6: getCommonTokenOffsetRange

import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
 * Returns a pointer to the start and end of the token image in the
 * underlaying stream. The token.getStopIndex() points to the last character
 * of the token which is a bit confusing.
 *
 * Use this method to get CommonToken's boundaries instead of using the
 * getStart/StopIndex methods.
 *
 * @return two members array - arr[0] is the start offset, arr[1] is the end
 * offset
 */
public static int[] getCommonTokenOffsetRange(CommonToken token) {
    if (token.getType() == CommonToken.EOF) {
        //"eof token" points at the end offset of the source, with zero length
        return new int[]{token.getStartIndex(), token.getStopIndex()};
    } else {
        return new int[]{token.getStartIndex(), token.getStopIndex() + 1};
    }

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CommonTokenUtil.java


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