本文整理匯總了Java中org.antlr.runtime.Token.HIDDEN_CHANNEL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Token.HIDDEN_CHANNEL屬性的具體用法?Java Token.HIDDEN_CHANNEL怎麽用?Java Token.HIDDEN_CHANNEL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.antlr.runtime.Token
的用法示例。
在下文中一共展示了Token.HIDDEN_CHANNEL屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: announce
@Override
protected void announce(Token start, Token stop, AbstractElement element) {
if (start != null && start != Token.EOF_TOKEN) {
if (start == stop) {
announce(start, element);
} else {
CommonToken castedStart = (CommonToken) start;
if (stop == null) { // possible error condition
if (start.getTokenIndex() == state.lastErrorIndex) {
return;
}
}
CommonToken castedEnd = (CommonToken) stop;
Integer newType = rewriter.rewrite(castedStart, element);
if (newType != null && castedEnd != null && castedEnd != Token.EOF_TOKEN) {
LazyTokenStream castedInput = (LazyTokenStream) this.input;
for (int i = castedStart.getTokenIndex() + 1; i < castedEnd.getTokenIndex(); i++) {
Token token = castedInput.get(i);
if (token.getChannel() != Token.HIDDEN_CHANNEL)
token.setType(newType);
}
castedEnd.setType(newType);
}
}
}
}
示例2: add
/**
* Adds token and adjust channel.
*/
@Override
public boolean add(Token tok) {
super.add(tok);
int type = tok.getType();
if (type == InternalN4JSParser.EqualsSignGreaterThanSign) {
// The arrow expression may not follow a semicolon thus we promote those here
// to he default channel if they precede the arrow => operator
for (int i = size() - 2; i >= 0; i--) {
Token prev = get(i);
if (prev.getChannel() == Token.HIDDEN_CHANNEL) {
if (SemicolonInjectionHelper.isSemicolonEquivalent(prev)) {
prev.setChannel(Token.DEFAULT_CHANNEL);
break;
}
} else {
break;
}
}
} else if (type == InternalN4JSParser.RULE_EOL
|| type == InternalN4JSParser.RULE_ML_COMMENT
|| type == InternalN4JSParser.RULE_WS
|| type == InternalN4JSParser.RULE_SL_COMMENT) {
tok.setChannel(Token.HIDDEN_CHANNEL);
} else {
tok.setChannel(Token.DEFAULT_CHANNEL);
}
return true;
}
示例3: skipHiddenTokens
protected void skipHiddenTokens() {
if (hiddenTokens == null || hiddenTokens.isEmpty())
return;
Token token = LT(1);
while(token.getChannel() == Token.HIDDEN_CHANNEL) {
p++;
token = LT(1);
}
}
示例4: nextToken
@Override
public Token nextToken() {
while (true) {
this.state.token = null;
this.state.channel = Token.DEFAULT_CHANNEL;
this.state.tokenStartCharIndex = input.index();
this.state.tokenStartCharPositionInLine = input.getCharPositionInLine();
this.state.tokenStartLine = input.getLine();
this.state.text = null;
if (input.LA(1) == CharStream.EOF) {
return Token.EOF_TOKEN;
}
try {
mTokens();
if (this.state.token == null) {
emit();
}
else if (this.state.token == Token.SKIP_TOKEN) {
continue;
}
return this.state.token;
}
catch (RecognitionException re) {
reportError(re);
if (re instanceof NoViableAltException ||
re instanceof FailedPredicateException) {
recover(re);
}
// create token that holds mismatched char
Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL,
this.state.tokenStartCharIndex, getCharIndex() - 1);
t.setLine(this.state.tokenStartLine);
t.setCharPositionInLine(this.state.tokenStartCharPositionInLine);
tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames()));
emit(t);
return this.state.token;
}
}
}