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    [System.Serializable]
41    public class NoViableAltException : RecognitionException
42    {
43        private readonly string _grammarDecisionDescription;
44        private readonly int _decisionNumber;
45        private readonly int _stateNumber;
46
47        public NoViableAltException()
48        {
49        }
50
51        public NoViableAltException(string grammarDecisionDescription)
52        {
53            this._grammarDecisionDescription = grammarDecisionDescription;
54        }
55
56        public NoViableAltException(string message, string grammarDecisionDescription)
57            : base(message)
58        {
59            this._grammarDecisionDescription = grammarDecisionDescription;
60        }
61
62        public NoViableAltException(string message, string grammarDecisionDescription, Exception innerException)
63            : base(message, innerException)
64        {
65            this._grammarDecisionDescription = grammarDecisionDescription;
66        }
67
68        public NoViableAltException(string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)
69            : base(input)
70        {
71            this._grammarDecisionDescription = grammarDecisionDescription;
72            this._decisionNumber = decisionNumber;
73            this._stateNumber = stateNumber;
74        }
75
76        public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input)
77            : base(message, input)
78        {
79            this._grammarDecisionDescription = grammarDecisionDescription;
80            this._decisionNumber = decisionNumber;
81            this._stateNumber = stateNumber;
82        }
83
84        public NoViableAltException(string message, string grammarDecisionDescription, int decisionNumber, int stateNumber, IIntStream input, Exception innerException)
85            : base(message, input, innerException)
86        {
87            this._grammarDecisionDescription = grammarDecisionDescription;
88            this._decisionNumber = decisionNumber;
89            this._stateNumber = stateNumber;
90        }
91
92        protected NoViableAltException(SerializationInfo info, StreamingContext context)
93            : base(info, context)
94        {
95            if (info == null)
96                throw new ArgumentNullException("info");
97
98            this._grammarDecisionDescription = info.GetString("GrammarDecisionDescription");
99            this._decisionNumber = info.GetInt32("DecisionNumber");
100            this._stateNumber = info.GetInt32("StateNumber");
101        }
102
103        public int DecisionNumber
104        {
105            get
106            {
107                return _decisionNumber;
108            }
109        }
110
111        public string GrammarDecisionDescription
112        {
113            get
114            {
115                return _grammarDecisionDescription;
116            }
117        }
118
119        public int StateNumber
120        {
121            get
122            {
123                return _stateNumber;
124            }
125        }
126
127        public override void GetObjectData(SerializationInfo info, StreamingContext context)
128        {
129            if (info == null)
130                throw new ArgumentNullException("info");
131
132            base.GetObjectData(info, context);
133            info.AddValue("GrammarDecisionDescription", _grammarDecisionDescription);
134            info.AddValue("DecisionNumber", _decisionNumber);
135            info.AddValue("StateNumber", _stateNumber);
136        }
137
138        public override string ToString()
139        {
140            if ( Input is ICharStream )
141            {
142                return "NoViableAltException('" + (char)UnexpectedType + "'@[" + GrammarDecisionDescription + "])";
143            }
144            else
145            {
146                return "NoViableAltException(" + UnexpectedType + "@[" + GrammarDecisionDescription + "])";
147            }
148        }
149    }
150}
151