Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / QueryParser / ParseException.cs
1 /* 
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
19 /* JavaCCOptions:KEEP_LINE_COL=null */
20
21 using System;
22
23 namespace Mono.Lucene.Net.QueryParsers
24 {
25         
26         /// <summary> This exception is thrown when parse errors are encountered.
27         /// You can explicitly create objects of this exception type by
28         /// calling the method generateParseException in the generated
29         /// parser.
30         /// 
31         /// You can modify this class to customize your error reporting
32         /// mechanisms so long as you retain the public fields.
33         /// </summary>
34         [Serializable]
35         public class ParseException:System.Exception
36         {
37                 /// <summary> This method has the standard behavior when this object has been
38                 /// created using the standard constructors.  Otherwise, it uses
39                 /// "currentToken" and "expectedTokenSequences" to generate a parse
40                 /// error message and returns it.  If this object has been created
41                 /// due to a parse error, and you do not catch it (it gets thrown
42                 /// from the parser), then this method is called during the printing
43                 /// of the final stack trace, and hence the correct error message
44                 /// gets displayed.
45                 /// </summary>
46                 public override System.String Message
47                 {
48                         get
49                         {
50                                 if (!specialConstructor)
51                                 {
52                                         return base.Message;
53                                 }
54                                 System.Text.StringBuilder expected = new System.Text.StringBuilder();
55                                 int maxSize = 0;
56                                 for (int i = 0; i < expectedTokenSequences.Length; i++)
57                                 {
58                                         if (maxSize < expectedTokenSequences[i].Length)
59                                         {
60                                                 maxSize = expectedTokenSequences[i].Length;
61                                         }
62                                         for (int j = 0; j < expectedTokenSequences[i].Length; j++)
63                                         {
64                                                 expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
65                                         }
66                                         if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
67                                         {
68                                                 expected.Append("...");
69                                         }
70                                         expected.Append(eol).Append("    ");
71                                 }
72                                 System.String retval = "Encountered \"";
73                                 Token tok = currentToken.next;
74                                 for (int i = 0; i < maxSize; i++)
75                                 {
76                                         if (i != 0)
77                                                 retval += " ";
78                                         if (tok.kind == 0)
79                                         {
80                                                 retval += tokenImage[0];
81                                                 break;
82                                         }
83                                         retval += (" " + tokenImage[tok.kind]);
84                                         retval += " \"";
85                                         retval += Add_escapes(tok.image);
86                                         retval += " \"";
87                                         tok = tok.next;
88                                 }
89                                 retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
90                                 retval += ("." + eol);
91                                 if (expectedTokenSequences.Length == 1)
92                                 {
93                                         retval += ("Was expecting:" + eol + "    ");
94                                 }
95                                 else
96                                 {
97                                         retval += ("Was expecting one of:" + eol + "    ");
98                                 }
99                                 retval += expected.ToString();
100                                 return retval;
101                         }
102                         
103                 }
104                 
105                 /// <summary> This constructor is used by the method "generateParseException"
106                 /// in the generated parser.  Calling this constructor generates
107                 /// a new object of this type with the fields "currentToken",
108                 /// "expectedTokenSequences", and "tokenImage" set.  The boolean
109                 /// flag "specialConstructor" is also set to true to indicate that
110                 /// this constructor was used to create this object.
111                 /// This constructor calls its super class with the empty string
112                 /// to force the "toString" method of parent class "Throwable" to
113                 /// print the error message in the form:
114         /// ParseException: &lt;result of getMessage&gt;
115                 /// </summary>
116                 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
117                 {
118                         specialConstructor = true;
119                         currentToken = currentTokenVal;
120                         expectedTokenSequences = expectedTokenSequencesVal;
121                         tokenImage = tokenImageVal;
122                 }
123                 
124                 /// <summary> The following constructors are for use by you for whatever
125                 /// purpose you can think of.  Constructing the exception in this
126                 /// manner makes the exception behave in the normal way - i.e., as
127                 /// documented in the class "Throwable".  The fields "errorToken",
128                 /// "expectedTokenSequences", and "tokenImage" do not contain
129                 /// relevant information.  The JavaCC generated code does not use
130                 /// these constructors.
131                 /// </summary>
132                 
133                 public ParseException():base()
134                 {
135                         specialConstructor = false;
136                 }
137                 
138                 /// <summary>Constructor with message. </summary>
139                 public ParseException(System.String message):base(message)
140                 {
141                         specialConstructor = false;
142                 }
143                 
144         /// <summary>Constructor with message. </summary>
145         public ParseException(System.String message, System.Exception ex) : base(message, ex)
146         {
147                 specialConstructor = false;
148         }
149                 
150                 /// <summary> This variable determines which constructor was used to create
151                 /// this object and thereby affects the semantics of the
152                 /// "getMessage" method (see below).
153                 /// </summary>
154                 protected internal bool specialConstructor;
155                 
156                 /// <summary> This is the last token that has been consumed successfully.  If
157                 /// this object has been created due to a parse error, the token
158                 /// followng this token will (therefore) be the first error token.
159                 /// </summary>
160                 public Token currentToken;
161                 
162                 /// <summary> Each entry in this array is an array of integers.  Each array
163                 /// of integers represents a sequence of tokens (by their ordinal
164                 /// values) that is expected at this point of the parse.
165                 /// </summary>
166                 public int[][] expectedTokenSequences;
167                 
168                 /// <summary> This is a reference to the "tokenImage" array of the generated
169                 /// parser within which the parse error occurred.  This array is
170                 /// defined in the generated ...Constants interface.
171                 /// </summary>
172                 public System.String[] tokenImage;
173                 
174                 /// <summary> The end of line string for this machine.</summary>
175                 protected internal System.String eol = SupportClass.AppSettings.Get("line.separator", "\n");
176                 
177                 /// <summary> Used to convert raw characters to their escaped version
178                 /// when these raw version cannot be used as part of an ASCII
179                 /// string literal.
180                 /// </summary>
181                 protected internal virtual System.String Add_escapes(System.String str)
182                 {
183                         System.Text.StringBuilder retval = new System.Text.StringBuilder();
184                         char ch;
185                         for (int i = 0; i < str.Length; i++)
186                         {
187                                 switch (str[i])
188                                 {
189                                         
190                                         case (char) (0): 
191                                                 continue;
192                                         
193                                         case '\b': 
194                                                 retval.Append("\\b");
195                                                 continue;
196                                         
197                                         case '\t': 
198                                                 retval.Append("\\t");
199                                                 continue;
200                                         
201                                         case '\n': 
202                                                 retval.Append("\\n");
203                                                 continue;
204                                         
205                                         case '\f': 
206                                                 retval.Append("\\f");
207                                                 continue;
208                                         
209                                         case '\r': 
210                                                 retval.Append("\\r");
211                                                 continue;
212                                         
213                                         case '\"': 
214                                                 retval.Append("\\\"");
215                                                 continue;
216                                         
217                                         case '\'': 
218                                                 retval.Append("\\\'");
219                                                 continue;
220                                         
221                                         case '\\': 
222                                                 retval.Append("\\\\");
223                                                 continue;
224                                         
225                                         default: 
226                                                 if ((ch = str[i]) < 0x20 || ch > 0x7e)
227                                                 {
228                                                         System.String s = "0000" + System.Convert.ToString(ch, 16);
229                                                         retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
230                                                 }
231                                                 else
232                                                 {
233                                                         retval.Append(ch);
234                                                 }
235                                                 continue;
236                                         
237                                 }
238                         }
239                         return retval.ToString();
240                 }
241         }
242         /* JavaCC - OriginalChecksum=c63b396885c4ff44d7aa48d3feae60cd (do not edit this line) */
243 }