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 3.0 */
19 
20 using System;
21 using Lucene.Net.Support;
22 
23 namespace Lucene.Net.Demo.Html
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 += Add_escapes(tok.image);
84  tok = tok.next;
85  }
86  retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
87  retval += ("." + eol);
88  if (expectedTokenSequences.Length == 1)
89  {
90  retval += ("Was expecting:" + eol + " ");
91  }
92  else
93  {
94  retval += ("Was expecting one of:" + eol + " ");
95  }
96  retval += expected.ToString();
97  return retval;
98  }
99 
100  }
101 
102  /// <summary> This constructor is used by the method "generateParseException"
103  /// in the generated parser. Calling this constructor generates
104  /// a new object of this type with the fields "currentToken",
105  /// "expectedTokenSequences", and "tokenImage" set. The boolean
106  /// flag "specialConstructor" is also set to true to indicate that
107  /// this constructor was used to create this object.
108  /// This constructor calls its super class with the empty string
109  /// to force the "toString" method of parent class "Throwable" to
110  /// print the error message in the form:
111  /// ParseException: &lt;result of getMessage&gt;
112  /// </summary>
113  public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
114  {
115  specialConstructor = true;
116  currentToken = currentTokenVal;
117  expectedTokenSequences = expectedTokenSequencesVal;
118  tokenImage = tokenImageVal;
119  }
120 
121  /// <summary> The following constructors are for use by you for whatever
122  /// purpose you can think of. Constructing the exception in this
123  /// manner makes the exception behave in the normal way - i.e., as
124  /// documented in the class "Throwable". The fields "errorToken",
125  /// "expectedTokenSequences", and "tokenImage" do not contain
126  /// relevant information. The JavaCC generated code does not use
127  /// these constructors.
128  /// </summary>
129 
130  public ParseException():base()
131  {
132  specialConstructor = false;
133  }
134 
135  public ParseException(System.String message):base(message)
136  {
137  specialConstructor = false;
138  }
139 
140  /// <summary> This variable determines which constructor was used to create
141  /// this object and thereby affects the semantics of the
142  /// "getMessage" method (see below).
143  /// </summary>
144  protected internal bool specialConstructor;
145 
146  /// <summary> This is the last token that has been consumed successfully. If
147  /// this object has been created due to a parse error, the token
148  /// followng this token will (therefore) be the first error token.
149  /// </summary>
151 
152  /// <summary> Each entry in this array is an array of integers. Each array
153  /// of integers represents a sequence of tokens (by their ordinal
154  /// values) that is expected at this point of the parse.
155  /// </summary>
156  public int[][] expectedTokenSequences;
157 
158  /// <summary> This is a reference to the "tokenImage" array of the generated
159  /// parser within which the parse error occurred. This array is
160  /// defined in the generated ...Constants interface.
161  /// </summary>
162  public System.String[] tokenImage;
163 
164  /// <summary> The end of line string for this machine.</summary>
165  protected internal System.String eol = AppSettings.Get("line.separator", "\n");
166 
167  /// <summary> Used to convert raw characters to their escaped version
168  /// when these raw version cannot be used as part of an ASCII
169  /// string literal.
170  /// </summary>
171  protected internal virtual System.String Add_escapes(System.String str)
172  {
173  System.Text.StringBuilder retval = new System.Text.StringBuilder();
174  char ch;
175  for (int i = 0; i < str.Length; i++)
176  {
177  switch (str[i])
178  {
179 
180  case (char) (0):
181  continue;
182 
183  case '\b':
184  retval.Append("\\b");
185  continue;
186 
187  case '\t':
188  retval.Append("\\t");
189  continue;
190 
191  case '\n':
192  retval.Append("\\n");
193  continue;
194 
195  case '\f':
196  retval.Append("\\f");
197  continue;
198 
199  case '\r':
200  retval.Append("\\r");
201  continue;
202 
203  case '\"':
204  retval.Append("\\\"");
205  continue;
206 
207  case '\'':
208  retval.Append("\\\'");
209  continue;
210 
211  case '\\':
212  retval.Append("\\\\");
213  continue;
214 
215  default:
216  if ((ch = str[i]) < 0x20 || ch > 0x7e)
217  {
218  System.String s = "0000" + System.Convert.ToString(ch, 16);
219  retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
220  }
221  else
222  {
223  retval.Append(ch);
224  }
225  continue;
226 
227  }
228  }
229  return retval.ToString();
230  }
231  }
232 }