forked from jasder/antlr
Merge branch 'failed-predicate-message' of git://github.com/sharwell/antlr4
This commit is contained in:
commit
a9e74ce399
|
@ -46,13 +46,13 @@ public class FailedPredicateException extends RecognitionException {
|
||||||
this(recognizer, null);
|
this(recognizer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FailedPredicateException(Parser recognizer, @Nullable String msg) {
|
public FailedPredicateException(Parser recognizer, @Nullable String predicate) {
|
||||||
super(recognizer, recognizer.getInputStream(), recognizer._ctx);
|
super(recognizer, recognizer.getInputStream(), recognizer._ctx);
|
||||||
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
|
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
|
||||||
PredicateTransition trans = (PredicateTransition)s.transition(0);
|
PredicateTransition trans = (PredicateTransition)s.transition(0);
|
||||||
ruleIndex = trans.ruleIndex;
|
ruleIndex = trans.ruleIndex;
|
||||||
predIndex = trans.predIndex;
|
predIndex = trans.predIndex;
|
||||||
this.msg = msg;
|
this.msg = String.format("failed predicate: {%s}?", predicate);
|
||||||
Token la = recognizer.getCurrentToken();
|
Token la = recognizer.getCurrentToken();
|
||||||
this.offendingToken = la;
|
this.offendingToken = la;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,10 @@ public class SemPred extends Action {
|
||||||
GrammarAST failNode = ((PredAST)ast).getOption("fail");
|
GrammarAST failNode = ((PredAST)ast).getOption("fail");
|
||||||
CodeGenerator gen = factory.getGenerator();
|
CodeGenerator gen = factory.getGenerator();
|
||||||
if ( failNode==null ) {
|
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);
|
msg = gen.target.getTargetStringLiteralFromString(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue