本文整理匯總了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;
}
示例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);
}
示例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("-------------");
}
示例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);
}
示例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);
}
示例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};
}
}