1/* 2 * [The "BSD licence"] 3 * Copyright (c) 2005-2008 Terence Parr 4 * All rights reserved. 5 * 6 * Conversion to C#: 7 * Copyright (c) 2008 Sam Harwell, Pixel Mine, Inc. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33namespace Antlr.Runtime 34{ 35 using ArgumentNullException = System.ArgumentNullException; 36 using Exception = System.Exception; 37 using SerializationInfo = System.Runtime.Serialization.SerializationInfo; 38 using StreamingContext = System.Runtime.Serialization.StreamingContext; 39 40 /** <summary> 41 * A semantic predicate failed during validation. Validation of predicates 42 * occurs when normally parsing the alternative just like matching a token. 43 * Disambiguating predicate evaluation occurs when we hoist a predicate into 44 * a prediction decision. 45 * </summary> 46 */ 47 [System.Serializable] 48 public class FailedPredicateException : RecognitionException 49 { 50 private readonly string _ruleName; 51 private readonly string _predicateText; 52 53 public FailedPredicateException() 54 { 55 } 56 57 public FailedPredicateException(string message) 58 : base(message) 59 { 60 } 61 62 public FailedPredicateException(string message, Exception innerException) 63 : base(message, innerException) 64 { 65 } 66 67 public FailedPredicateException(IIntStream input, string ruleName, string predicateText) 68 : base(input) 69 { 70 this._ruleName = ruleName; 71 this._predicateText = predicateText; 72 } 73 74 public FailedPredicateException(string message, IIntStream input, string ruleName, string predicateText) 75 : base(message, input) 76 { 77 this._ruleName = ruleName; 78 this._predicateText = predicateText; 79 } 80 81 public FailedPredicateException(string message, IIntStream input, string ruleName, string predicateText, Exception innerException) 82 : base(message, input, innerException) 83 { 84 this._ruleName = ruleName; 85 this._predicateText = predicateText; 86 } 87 88 protected FailedPredicateException(SerializationInfo info, StreamingContext context) 89 : base(info, context) 90 { 91 if (info == null) 92 throw new ArgumentNullException("info"); 93 94 this._ruleName = info.GetString("RuleName"); 95 this._predicateText = info.GetString("PredicateText"); 96 } 97 98 public string RuleName 99 { 100 get 101 { 102 return _ruleName; 103 } 104 } 105 106 public string PredicateText 107 { 108 get 109 { 110 return _predicateText; 111 } 112 } 113 114 public override void GetObjectData(SerializationInfo info, StreamingContext context) 115 { 116 if (info == null) 117 throw new ArgumentNullException("info"); 118 119 base.GetObjectData(info, context); 120 info.AddValue("RuleName", _ruleName); 121 info.AddValue("PredicateText", _predicateText); 122 } 123 124 public override string ToString() 125 { 126 return "FailedPredicateException(" + RuleName + ",{" + PredicateText + "}?)"; 127 } 128 } 129} 130