Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
ParseException.cs
Go to the documentation of this file.
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 using Lucene.Net.Support;
23 
24 namespace Lucene.Net.QueryParsers
25 {
26 
27  /// <summary> This exception is thrown when parse errors are encountered.
28  /// You can explicitly create objects of this exception type by
29  /// calling the method generateParseException in the generated
30  /// parser.
31  ///
32  /// You can modify this class to customize your error reporting
33  /// mechanisms so long as you retain the public fields.
34  /// </summary>
35  [Serializable]
36  public class ParseException:System.Exception
37  {
38  /// <summary> This method has the standard behavior when this object has been
39  /// created using the standard constructors. Otherwise, it uses
40  /// "currentToken" and "expectedTokenSequences" to generate a parse
41  /// error message and returns it. If this object has been created
42  /// due to a parse error, and you do not catch it (it gets thrown
43  /// from the parser), then this method is called during the printing
44  /// of the final stack trace, and hence the correct error message
45  /// gets displayed.
46  /// </summary>
47  public override System.String Message
48  {
49  get
50  {
51  if (!specialConstructor)
52  {
53  return base.Message;
54  }
55  System.Text.StringBuilder expected = new System.Text.StringBuilder();
56  int maxSize = 0;
57  for (int i = 0; i < expectedTokenSequences.Length; i++)
58  {
59  if (maxSize < expectedTokenSequences[i].Length)
60  {
61  maxSize = expectedTokenSequences[i].Length;
62  }
63  for (int j = 0; j < expectedTokenSequences[i].Length; j++)
64  {
65  expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
66  }
67  if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
68  {
69  expected.Append("...");
70  }
71  expected.Append(eol).Append(" ");
72  }
73  System.String retval = "Encountered \"";
74  Token tok = currentToken.next;
75  for (int i = 0; i < maxSize; i++)
76  {
77  if (i != 0)
78  retval += " ";
79  if (tok.kind == 0)
80  {
81  retval += tokenImage[0];
82  break;
83  }
84  retval += (" " + tokenImage[tok.kind]);
85  retval += " \"";
86  retval += Add_escapes(tok.image);
87  retval += " \"";
88  tok = tok.next;
89  }
90  retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
91  retval += ("." + eol);
92  if (expectedTokenSequences.Length == 1)
93  {
94  retval += ("Was expecting:" + eol + " ");
95  }
96  else
97  {
98  retval += ("Was expecting one of:" + eol + " ");
99  }
100  retval += expected.ToString();
101  return retval;
102  }
103 
104  }
105 
106  /// <summary> This constructor is used by the method "generateParseException"
107  /// in the generated parser. Calling this constructor generates
108  /// a new object of this type with the fields "currentToken",
109  /// "expectedTokenSequences", and "tokenImage" set. The boolean
110  /// flag "specialConstructor" is also set to true to indicate that
111  /// this constructor was used to create this object.
112  /// This constructor calls its super class with the empty string
113  /// to force the "toString" method of parent class "Throwable" to
114  /// print the error message in the form:
115  /// ParseException: &lt;result of getMessage&gt;
116  /// </summary>
117  public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
118  {
119  specialConstructor = true;
120  currentToken = currentTokenVal;
121  expectedTokenSequences = expectedTokenSequencesVal;
122  tokenImage = tokenImageVal;
123  }
124 
125  /// <summary> The following constructors are for use by you for whatever
126  /// purpose you can think of. Constructing the exception in this
127  /// manner makes the exception behave in the normal way - i.e., as
128  /// documented in the class "Throwable". The fields "errorToken",
129  /// "expectedTokenSequences", and "tokenImage" do not contain
130  /// relevant information. The JavaCC generated code does not use
131  /// these constructors.
132  /// </summary>
133 
134  public ParseException():base()
135  {
136  specialConstructor = false;
137  }
138 
139  /// <summary>Constructor with message. </summary>
140  public ParseException(System.String message):base(message)
141  {
142  specialConstructor = false;
143  }
144 
145  /// <summary>Constructor with message. </summary>
146  public ParseException(System.String message, System.Exception ex) : base(message, ex)
147  {
148  specialConstructor = false;
149  }
150 
151  /// <summary> This variable determines which constructor was used to create
152  /// this object and thereby affects the semantics of the
153  /// "getMessage" method (see below).
154  /// </summary>
155  protected internal bool specialConstructor;
156 
157  /// <summary> This is the last token that has been consumed successfully. If
158  /// this object has been created due to a parse error, the token
159  /// followng this token will (therefore) be the first error token.
160  /// </summary>
162 
163  /// <summary> Each entry in this array is an array of integers. Each array
164  /// of integers represents a sequence of tokens (by their ordinal
165  /// values) that is expected at this point of the parse.
166  /// </summary>
167  public int[][] expectedTokenSequences;
168 
169  /// <summary> This is a reference to the "tokenImage" array of the generated
170  /// parser within which the parse error occurred. This array is
171  /// defined in the generated ...Constants interface.
172  /// </summary>
173  public System.String[] tokenImage;
174 
175  /// <summary> The end of line string for this machine.</summary>
176  protected internal System.String eol = AppSettings.Get("line.separator", "\n");
177 
178  /// <summary> Used to convert raw characters to their escaped version
179  /// when these raw version cannot be used as part of an ASCII
180  /// string literal.
181  /// </summary>
182  protected internal virtual System.String Add_escapes(System.String str)
183  {
184  System.Text.StringBuilder retval = new System.Text.StringBuilder();
185  char ch;
186  for (int i = 0; i < str.Length; i++)
187  {
188  switch (str[i])
189  {
190 
191  case (char) (0):
192  continue;
193 
194  case '\b':
195  retval.Append("\\b");
196  continue;
197 
198  case '\t':
199  retval.Append("\\t");
200  continue;
201 
202  case '\n':
203  retval.Append("\\n");
204  continue;
205 
206  case '\f':
207  retval.Append("\\f");
208  continue;
209 
210  case '\r':
211  retval.Append("\\r");
212  continue;
213 
214  case '\"':
215  retval.Append("\\\"");
216  continue;
217 
218  case '\'':
219  retval.Append("\\\'");
220  continue;
221 
222  case '\\':
223  retval.Append("\\\\");
224  continue;
225 
226  default:
227  if ((ch = str[i]) < 0x20 || ch > 0x7e)
228  {
229  System.String s = "0000" + System.Convert.ToString(ch, 16);
230  retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
231  }
232  else
233  {
234  retval.Append(ch);
235  }
236  continue;
237 
238  }
239  }
240  return retval.ToString();
241  }
242  }
243  /* JavaCC - OriginalChecksum=c7631a240f7446940695eac31d9483ca (do not edit this line) */
244 }