forked from jasder/antlr
Reduce size of generated code by emitting predicate text instead of full failed predicate message
This commit is contained in:
parent
dd69a7532d
commit
c3cd99858c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue