本文整理汇总了Java中org.antlr.runtime.BaseRecognizer.getErrorHeader方法的典型用法代码示例。如果您正苦于以下问题:Java BaseRecognizer.getErrorHeader方法的具体用法?Java BaseRecognizer.getErrorHeader怎么用?Java BaseRecognizer.getErrorHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.BaseRecognizer
的用法示例。
在下文中一共展示了BaseRecognizer.getErrorHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syntaxError
import org.antlr.runtime.BaseRecognizer; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void syntaxError(BaseRecognizer recognizer, String[] tokenNames, RecognitionException e)
{
String hdr = recognizer.getErrorHeader(e);
String msg = recognizer.getErrorMessage(e, tokenNames);
StringBuilder builder = new StringBuilder().append(hdr)
.append(' ')
.append(msg);
if (recognizer instanceof Parser)
appendQuerySnippet((Parser) recognizer, builder);
errorMsgs.add(builder.toString());
}
示例2: getErrorMessage
import org.antlr.runtime.BaseRecognizer; //导入方法依赖的package包/类
/**
* Format an error message as expected by ANTLR. It is basically the
* same error message that ANTL BaseRecognizer generates with some
* additional data.
* Also used to log debugging information.
* @param log the logger to use at debug time
* @param recognizer the lexer or parser who generated the error
* @param e the exception that occured
* @param superMessage the error message that the super class generated
* @param tokenNames list of token names
* @return a formatted error message
*/
public static String getErrorMessage(
final Log log,
final BaseRecognizer recognizer,
final RecognitionException e,
final String superMessage,
final String[] tokenNames) {
if (log.isDebugEnabled()) {
List < ? > stack = BaseRecognizer.getRuleInvocationStack(
e, recognizer.getClass().getSuperclass().getName());
String debugMsg = recognizer.getErrorHeader(e)
+ " " + e.getClass().getSimpleName()
+ ": " + superMessage
+ ":";
if (e instanceof NoViableAltException) {
NoViableAltException nvae = (NoViableAltException) e;
debugMsg += " (decision=" + nvae.decisionNumber
+ " state=" + nvae.stateNumber + ")"
+ " decision=<<" + nvae.grammarDecisionDescription + ">>";
} else if (e instanceof UnwantedTokenException) {
UnwantedTokenException ute = (UnwantedTokenException) e;
debugMsg += " (unexpected token=" + toString(ute.getUnexpectedToken(), tokenNames) + ")";
} else if (e instanceof EarlyExitException) {
EarlyExitException eea = (EarlyExitException) e;
debugMsg += " (decision=" + eea.decisionNumber + ")";
}
debugMsg += " ruleStack=" + stack.toString();
log.debug(debugMsg);
}
return makeUserMsg(e, superMessage);
}
示例3: getErrorMessage
import org.antlr.runtime.BaseRecognizer; //导入方法依赖的package包/类
/**
* Format an error message as expected by ANTLR. It is basically the
* same error message that ANTL BaseRecognizer generates with some
* additional data.
* Also used to log debugging information.
* @param log the logger to use at debug time
* @param recognizer the lexer or parser who generated the error
* @param e the exception that occured
* @param superMessage the error message that the super class generated
* @param tokenNames list of token names
* @return a formatted error message
*/
public static String getErrorMessage(
final Logger log,
final BaseRecognizer recognizer,
final RecognitionException e,
final String superMessage,
final String[] tokenNames) {
if (log.isDebugEnabled()) {
List < ? > stack = BaseRecognizer.getRuleInvocationStack(
e, recognizer.getClass().getSuperclass().getName());
String debugMsg = recognizer.getErrorHeader(e)
+ " " + e.getClass().getSimpleName()
+ ": " + superMessage
+ ":";
if (e instanceof NoViableAltException) {
NoViableAltException nvae = (NoViableAltException) e;
debugMsg += " (decision=" + nvae.decisionNumber
+ " state=" + nvae.stateNumber + ")"
+ " decision=<<" + nvae.grammarDecisionDescription + ">>";
} else if (e instanceof UnwantedTokenException) {
UnwantedTokenException ute = (UnwantedTokenException) e;
debugMsg += " (unexpected token=" + toString(ute.getUnexpectedToken(), tokenNames) + ")";
} else if (e instanceof EarlyExitException) {
EarlyExitException eea = (EarlyExitException) e;
debugMsg += " (decision=" + eea.decisionNumber + ")";
}
debugMsg += " ruleStack=" + stack.toString();
log.debug(debugMsg);
}
return makeUserMsg(e, superMessage);
}