本文整理汇总了Java中org.antlr.v4.runtime.Parser.getCurrentToken方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.getCurrentToken方法的具体用法?Java Parser.getCurrentToken怎么用?Java Parser.getCurrentToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.Parser
的用法示例。
在下文中一共展示了Parser.getCurrentToken方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportUnwantedToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void reportUnwantedToken(@NotNull Parser recognizer)
{
if (inErrorRecoveryMode(recognizer))
{
return;
}
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = getTokenErrorDisplay(t);
IntervalSet expecting = getExpectedTokens(recognizer);
String msg = "多余输入 " + tokenName + " 期望 " + expecting.toString(recognizer.getTokenNames());
BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg);
// exception.token = this.getGrammarToken(t);
exception.pushToken(this.getGrammarToken(t));
throw exception;
}
示例2: reportUnwantedToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
@Override
protected void reportUnwantedToken(Parser recognizer) {
// change error message from default implementation
if (inErrorRecoveryMode(recognizer)) {
return;
}
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = getTokenErrorDisplay(t);
String msg = "extraneous input " + tokenName + " expecting operator";
recognizer.notifyErrorListeners(t, msg, null);
}
示例3: recoverInline
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
@Override
public Token recoverInline(final Parser recognizer) throws RecognitionException {
final Token token = recognizer.getCurrentToken();
final String message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
" was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
Location location = new Location(sourceName, token.getStartIndex());
throw location.createError(new IllegalArgumentException(message));
}
示例4: reportMissingToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
@Override
public void reportMissingToken(Parser recognizer) {
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
IntervalSet expecting = getExpectedTokens(recognizer);
String msg = "missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t);
throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
}
示例5: reportUnwantedToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void reportUnwantedToken(Parser recognizer) {
if (!this.inErrorRecoveryMode(recognizer)) {
this.beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
String tokenName = this.getTokenErrorDisplay(t);
IntervalSet expecting = this.getExpectedTokens(recognizer);
String msg =
"extraneous input " + tokenName + " expecting "
+ expecting.toString(recognizer.getVocabulary());
recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
}
}
示例6: reportMissingToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void reportMissingToken(Parser recognizer) {
if (!this.inErrorRecoveryMode(recognizer)) {
this.beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
IntervalSet expecting = this.getExpectedTokens(recognizer);
String msg =
"missing " + expecting.toString(recognizer.getVocabulary()) + " at " + this
.getTokenErrorDisplay(t);
recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
}
}
示例7: consumeUntil
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
@Override
protected void consumeUntil(Parser recognizer, IntervalSet set) {
Token o = recognizer.getCurrentToken();
if ( o.getType()==Token.EOF ) {
recognizer.getRuleContext().addErrorNode(o);
}
super.consumeUntil(recognizer, set);
}
示例8: getMissingSymbol
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
/** By default ANTLR makes the start/stop -1/-1 for invalid tokens
* which is reasonable but here we want to highlight the
* current position indicating that is where we lack a token.
* if no input, highlight at position 0.
*/
protected Token getMissingSymbol(Parser recognizer) {
Token missingSymbol = super.getMissingSymbol(recognizer);
// alter the default missing symbol.
if ( missingSymbol instanceof CommonToken) {
int start, stop;
Token current = recognizer.getCurrentToken();
start = current.getStartIndex();
stop = current.getStopIndex();
((CommonToken) missingSymbol).setStartIndex(start);
((CommonToken) missingSymbol).setStopIndex(stop);
}
return missingSymbol;
}
示例9: reportMissingToken
import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
@Override
public void reportMissingToken(Parser recognizer) {
beginErrorCondition(recognizer);
Token t = recognizer.getCurrentToken();
IntervalSet expecting = getExpectedTokens(recognizer);
String msg = "";
msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine() + ": ";
msg += "Missing "+expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t) + ";";
//msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column " + recognizer.getContext().start.getCharPositionInLine() + ";";
throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
}