Merge branch 'failed-predicate-message' of git://github.com/sharwell/antlr4

This commit is contained in:
Terence Parr 2012-03-06 13:28:47 -08:00
commit a9e74ce399
2 changed files with 6 additions and 3 deletions

View File

@ -46,13 +46,13 @@ public class FailedPredicateException extends RecognitionException {
this(recognizer, null);
}
public FailedPredicateException(Parser recognizer, @Nullable String msg) {
public FailedPredicateException(Parser recognizer, @Nullable String predicate) {
super(recognizer, recognizer.getInputStream(), recognizer._ctx);
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
PredicateTransition trans = (PredicateTransition)s.transition(0);
ruleIndex = trans.ruleIndex;
predIndex = trans.predIndex;
this.msg = msg;
this.msg = String.format("failed predicate: {%s}?", predicate);
Token la = recognizer.getCurrentToken();
this.offendingToken = la;
}

View File

@ -50,7 +50,10 @@ public class SemPred extends Action {
GrammarAST failNode = ((PredAST)ast).getOption("fail");
CodeGenerator gen = factory.getGenerator();
if ( failNode==null ) {
msg = "failed predicate: "+ast.getText();
msg = ast.getText();
if (msg.startsWith("{") && msg.endsWith("}?")) {
msg = msg.substring(1, msg.length() - 2);
}
msg = gen.target.getTargetStringLiteralFromString(msg);
return;
}