• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * [The "BSD license"]
3  * Copyright (c) 2011 Terence Parr
4  * All rights reserved.
5  *
6  * Conversion to C#:
7  * Copyright (c) 2011 Sam Harwell, Tunnel Vision Laboratories, LLC
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 
33 namespace 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     [System.Serializable]
41     public class NoViableAltException : RecognitionException
42     {
43         private readonly string _grammarDecisionDescription;
44         private readonly int _decisionNumber;
45         private readonly int _stateNumber;
46 
NoViableAltException()47         public NoViableAltException()
48         {
49         }
50 
NoViableAltException(string grammarDecisionDescription)51         public NoViableAltException(string grammarDecisionDescription)
52         {
53             this._grammarDecisionDescription = grammarDecisionDescription;
54         }
55 
NoViableAltException(string message, string grammarDecisionDescription)56         public NoViableAltException(string message, string grammarDecisionDescription)
57             : base(message)
58         {
59             this._grammarDecisionDescription = grammarDecisionDescription;
60         }
61 
NoViableAltException(string message, string grammarDecisionDescription, Exception innerException)62         public NoViableAltException(string message, string grammarDecisionDescription, Exception innerException)
63             : base(message, innerException)
64         {
65             this._grammarDecisionDescription = grammarDecisionDescription;
66         }
67 
NoViableAltException(string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)68         public NoViableAltException(string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)
69             : this(grammarDecisionDescription, decisionNumber, stateNumber, input, 1)
70         {
71         }
72 
NoViableAltException(string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k)73         public NoViableAltException(string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k)
74             : base(input, k)
75         {
76             this._grammarDecisionDescription = grammarDecisionDescription;
77             this._decisionNumber = decisionNumber;
78             this._stateNumber = stateNumber;
79         }
80 
NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)81         public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)
82             : this(message, grammarDecisionDescription, decisionNumber, stateNumber, input, 1)
83         {
84         }
85 
NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k)86         public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k)
87             : base(message, input, k)
88         {
89             this._grammarDecisionDescription = grammarDecisionDescription;
90             this._decisionNumber = decisionNumber;
91             this._stateNumber = stateNumber;
92         }
93 
NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, Exception innerException)94         public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, Exception innerException)
95             : this(message, grammarDecisionDescription, decisionNumber, stateNumber, input, 1, innerException)
96         {
97         }
98 
NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k, Exception innerException)99         public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, int k, Exception innerException)
100             : base(message, input, k, innerException)
101         {
102             this._grammarDecisionDescription = grammarDecisionDescription;
103             this._decisionNumber = decisionNumber;
104             this._stateNumber = stateNumber;
105         }
106 
NoViableAltException(SerializationInfo info, StreamingContext context)107         protected NoViableAltException(SerializationInfo info, StreamingContext context)
108             : base(info, context)
109         {
110             if (info == null)
111                 throw new ArgumentNullException("info");
112 
113             this._grammarDecisionDescription = info.GetString("GrammarDecisionDescription");
114             this._decisionNumber = info.GetInt32("DecisionNumber");
115             this._stateNumber = info.GetInt32("StateNumber");
116         }
117 
118         public int DecisionNumber
119         {
120             get
121             {
122                 return _decisionNumber;
123             }
124         }
125 
126         public string GrammarDecisionDescription
127         {
128             get
129             {
130                 return _grammarDecisionDescription;
131             }
132         }
133 
134         public int StateNumber
135         {
136             get
137             {
138                 return _stateNumber;
139             }
140         }
141 
GetObjectData(SerializationInfo info, StreamingContext context)142         public override void GetObjectData(SerializationInfo info, StreamingContext context)
143         {
144             if (info == null)
145                 throw new ArgumentNullException("info");
146 
147             base.GetObjectData(info, context);
148             info.AddValue("GrammarDecisionDescription", _grammarDecisionDescription);
149             info.AddValue("DecisionNumber", _decisionNumber);
150             info.AddValue("StateNumber", _stateNumber);
151         }
152 
ToString()153         public override string ToString()
154         {
155             if ( Input is ICharStream )
156             {
157                 return "NoViableAltException('" + (char)UnexpectedType + "'@[" + GrammarDecisionDescription + "])";
158             }
159             else
160             {
161                 return "NoViableAltException(" + UnexpectedType + "@[" + GrammarDecisionDescription + "])";
162             }
163         }
164     }
165 }
166