本文整理汇总了Java中org.antlr.v4.runtime.CommonToken.setType方法的典型用法代码示例。如果您正苦于以下问题:Java CommonToken.setType方法的具体用法?Java CommonToken.setType怎么用?Java CommonToken.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.CommonToken
的用法示例。
在下文中一共展示了CommonToken.setType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createToken
import org.antlr.v4.runtime.CommonToken; //导入方法依赖的package包/类
private Token createToken(int tokenType, Token copyFrom) {
String tokenTypeStr;
if (tokenType == nlToken) {
tokenTypeStr = "newline";
} else if (tokenType == indentToken) {
tokenTypeStr = "indent";
} else if (tokenType == dedentToken) {
tokenTypeStr = "dedent";
} else {
tokenTypeStr = null;
}
CommonToken r = new InjectedToken(copyFrom, tokenTypeStr);
r.setType(tokenType);
return r;
}
示例2: setIndexOfLastToken
import org.antlr.v4.runtime.CommonToken; //导入方法依赖的package包/类
public void setIndexOfLastToken(int indexOfLastToken) {
System.out.println("setIndexOfLastToken("+indexOfLastToken+")");
if ( indexOfLastToken<0 ) {
System.out.println("replacing "+saveToken.getTokenIndex()+" with "+saveToken);
tokens.set(saveToken.getTokenIndex(), saveToken);
// this.indexOfLastToken = indexOfLastToken;
return;
}
int i = indexOfLastToken + 1; // we want to keep token at indexOfLastToken
sync(i);
saveToken = tokens.get(i);
System.out.println("saving "+saveToken);
CommonToken stopToken = new CommonToken(saveToken);
stopToken.setType(STOP_TOKEN_TYPE);
System.out.println("setting "+i+" to "+stopToken);
tokens.set(i, stopToken);
// this.indexOfLastToken = indexOfLastToken;
}
示例3: exitUnary
import org.antlr.v4.runtime.CommonToken; //导入方法依赖的package包/类
@Override
public void exitUnary(UnaryContext ctx) {
if (ctx.getChildCount() == 1) {
return;
}
final Token token;
if (ctx.cast() != null) {
CommonToken ct = new CommonToken(ctx.cast().type);
switch (ct.getText()) {
case "long":
ct.setType(CAST_LONG);
break;
case "bool":
ct.setType(CAST_BOOL);
break;
case "string":
ct.setType(CAST_STRING);
break;
case "double":
ct.setType(CAST_DOUBLE);
break;
}
token = ct;
} else {
token = ctx.getStart();
}
Expression arg = stack.pop();
if (token.getType() != COUNT) {
arg = dereference(token, arg, null);
}
stack.push(ExpressionFactory.createOpExpr(token, arg));
}