Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / Standard / ParseException.cs
blob25b399b02246aa1923f26f9cacb7a5e728639b10
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
17 using System;
18 namespace Lucene.Net.Analysis.Standard
21 /// <summary> This exception is thrown when parse errors are encountered.
22 /// You can explicitly create objects of this exception type by
23 /// calling the method generateParseException in the generated
24 /// parser.
25 ///
26 /// You can modify this class to customize your error reporting
27 /// mechanisms so long as you retain the public fields.
28 /// </summary>
29 [Serializable]
30 public class ParseException : System.IO.IOException
32 /// <summary> This method has the standard behavior when this object has been
33 /// created using the standard constructors. Otherwise, it uses
34 /// "currentToken" and "expectedTokenSequences" to generate a parse
35 /// error message and returns it. If this object has been created
36 /// due to a parse error, and you do not catch it (it gets thrown
37 /// from the parser), then this method is called during the printing
38 /// of the final stack trace, and hence the correct error message
39 /// gets displayed.
40 /// </summary>
41 public override System.String Message
43 get
45 if (!specialConstructor)
47 return base.Message;
49 System.String expected = "";
50 int maxSize = 0;
51 for (int i = 0; i < expectedTokenSequences.Length; i++)
53 if (maxSize < expectedTokenSequences[i].Length)
55 maxSize = expectedTokenSequences[i].Length;
57 for (int j = 0; j < expectedTokenSequences[i].Length; j++)
59 expected += (tokenImage[expectedTokenSequences[i][j]] + " ");
61 if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
63 expected += "...";
65 expected += (eol + " ");
67 System.String retval = "Encountered \"";
68 Token tok = currentToken.next;
69 for (int i = 0; i < maxSize; i++)
71 if (i != 0)
72 retval += " ";
73 if (tok.kind == 0)
75 retval += tokenImage[0];
76 break;
78 retval += Add_escapes(tok.image);
79 tok = tok.next;
81 retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + eol);
82 if (expectedTokenSequences.Length == 1)
84 retval += ("Was expecting:" + eol + " ");
86 else
88 retval += ("Was expecting one of:" + eol + " ");
90 retval += expected;
91 return retval;
96 /// <summary> This constructor is used by the method "generateParseException"
97 /// in the generated parser. Calling this constructor generates
98 /// a new object of this type with the fields "currentToken",
99 /// "expectedTokenSequences", and "tokenImage" set. The boolean
100 /// flag "specialConstructor" is also set to true to indicate that
101 /// this constructor was used to create this object.
102 /// This constructor calls its super class with the empty string
103 /// to force the "toString" method of parent class "Throwable" to
104 /// print the error message in the form:
105 /// ParseException: &lt;result of getMessage&gt;
106 /// </summary>
107 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal) : base("")
109 eol = System.Configuration.ConfigurationSettings.AppSettings.Get("line.separator");
110 if (eol == null)
112 eol = "\n";
114 specialConstructor = true;
115 currentToken = currentTokenVal;
116 expectedTokenSequences = expectedTokenSequencesVal;
117 tokenImage = tokenImageVal;
120 /// <summary> The following constructors are for use by you for whatever
121 /// purpose you can think of. Constructing the exception in this
122 /// manner makes the exception behave in the normal way - i.e., as
123 /// documented in the class "Throwable". The fields "errorToken",
124 /// "expectedTokenSequences", and "tokenImage" do not contain
125 /// relevant information. The JavaCC generated code does not use
126 /// these constructors.
127 /// </summary>
129 public ParseException() : base()
131 eol = System.Configuration.ConfigurationSettings.AppSettings.Get("line.separator");
132 if (eol == null)
134 eol = "\n";
137 specialConstructor = false;
140 public ParseException(System.String message) : base(message)
142 eol = System.Configuration.ConfigurationSettings.AppSettings.Get("line.separator");
143 if (eol == null)
145 eol = "\n";
148 specialConstructor = false;
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;
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>
161 public Token currentToken;
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;
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;
175 /// <summary> The end of line string for this machine.</summary>
176 protected internal System.String eol = System.Configuration.ConfigurationSettings.AppSettings.Get("line.separator");
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)
184 System.Text.StringBuilder retval = new System.Text.StringBuilder();
185 char ch;
186 for (int i = 0; i < str.Length; i++)
188 switch (str[i])
191 case (char) (0):
192 continue;
194 case '\b':
195 retval.Append("\\b");
196 continue;
198 case '\t':
199 retval.Append("\\t");
200 continue;
202 case '\n':
203 retval.Append("\\n");
204 continue;
206 case '\f':
207 retval.Append("\\f");
208 continue;
210 case '\r':
211 retval.Append("\\r");
212 continue;
214 case '\"':
215 retval.Append("\\\"");
216 continue;
218 case '\'':
219 retval.Append("\\\'");
220 continue;
222 case '\\':
223 retval.Append("\\\\");
224 continue;
226 default:
227 if ((ch = str[i]) < 0x20 || ch > 0x7e)
229 System.String s = "0000" + System.Convert.ToString(ch, 16);
230 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
232 else
234 retval.Append(ch);
236 continue;
240 return retval.ToString();