1 module antlr.v4.runtime.FailedPredicateException; 2 3 import std.format; 4 import antlr.v4.runtime.RecognitionException; 5 import antlr.v4.runtime.Token; 6 import antlr.v4.runtime.Parser; 7 import antlr.v4.runtime.atn.ATNState; 8 import antlr.v4.runtime.atn.AbstractPredicateTransition; 9 import antlr.v4.runtime.atn.PredicateTransition; 10 11 // Class FailedPredicateException 12 /** 13 * TODO add class description 14 */ 15 class FailedPredicateException : RecognitionException 16 { 17 18 private int ruleIndex; 19 20 private int predicateIndex; 21 22 private string predicate; 23 24 public this(Parser recognizer) 25 { 26 this(recognizer, null); 27 } 28 29 public this(Parser recognizer, string predicate) 30 { 31 this(recognizer, predicate, null); 32 } 33 34 public this(Parser recognizer, string predicate, string message) 35 { 36 super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer.ctx_); 37 ATNState s = recognizer.getInterpreter().atn.states[recognizer.getState]; 38 39 AbstractPredicateTransition trans = cast(AbstractPredicateTransition)s.transition(0); 40 if (trans.classinfo == PredicateTransition.classinfo) { 41 this.ruleIndex = (cast(PredicateTransition)trans).ruleIndex; 42 this.predicateIndex = (cast(PredicateTransition)trans).predIndex; 43 } 44 else { 45 this.ruleIndex = 0; 46 this.predicateIndex = 0; 47 } 48 49 this.predicate = predicate; 50 this.setOffendingToken(recognizer.getCurrentToken()); 51 52 } 53 54 public int getRuleIndex() 55 { 56 return ruleIndex; 57 } 58 59 public int getPredIndex() 60 { 61 return predicateIndex; 62 } 63 64 public string getPredicate() 65 { 66 return predicate; 67 } 68 69 private static string formatMessage(string predicate, string message) 70 { 71 if (message !is null) { 72 return message; 73 } 74 return format("failed predicate: {%s}?", predicate); 75 } 76 77 }