Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / QueryParser / ParseException.cs
blobea092ee4c22c9e72b66cd2ac802161a474aeb02b
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 3.0 */
17 using System;
18 namespace Lucene.Net.QueryParsers
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.Exception
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);
82 retval += ("." + eol);
83 if (expectedTokenSequences.Length == 1)
85 retval += ("Was expecting:" + eol + " ");
87 else
89 retval += ("Was expecting one of:" + eol + " ");
91 retval += expected;
92 return retval;
97 /// <summary> This constructor is used by the method "generateParseException"
98 /// in the generated parser. Calling this constructor generates
99 /// a new object of this type with the fields "currentToken",
100 /// "expectedTokenSequences", and "tokenImage" set. The boolean
101 /// flag "specialConstructor" is also set to true to indicate that
102 /// this constructor was used to create this object.
103 /// This constructor calls its super class with the empty string
104 /// to force the "toString" method of parent class "Throwable" to
105 /// print the error message in the form:
106 /// ParseException: <result of getMessage>
107 /// </summary>
108 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
110 specialConstructor = true;
111 currentToken = currentTokenVal;
112 expectedTokenSequences = expectedTokenSequencesVal;
113 tokenImage = tokenImageVal;
116 /// <summary> The following constructors are for use by you for whatever
117 /// purpose you can think of. Constructing the exception in this
118 /// manner makes the exception behave in the normal way - i.e., as
119 /// documented in the class "Throwable". The fields "errorToken",
120 /// "expectedTokenSequences", and "tokenImage" do not contain
121 /// relevant information. The JavaCC generated code does not use
122 /// these constructors.
123 /// </summary>
125 public ParseException():base()
127 specialConstructor = false;
130 public ParseException(System.String message) : base(message)
132 specialConstructor = false;
135 /// <summary> This variable determines which constructor was used to create
136 /// this object and thereby affects the semantics of the
137 /// "getMessage" method (see below).
138 /// </summary>
139 protected internal bool specialConstructor;
141 /// <summary> This is the last token that has been consumed successfully. If
142 /// this object has been created due to a parse error, the token
143 /// followng this token will (therefore) be the first error token.
144 /// </summary>
145 public Token currentToken;
147 /// <summary> Each entry in this array is an array of integers. Each array
148 /// of integers represents a sequence of tokens (by their ordinal
149 /// values) that is expected at this point of the parse.
150 /// </summary>
151 public int[][] expectedTokenSequences;
153 /// <summary> This is a reference to the "tokenImage" array of the generated
154 /// parser within which the parse error occurred. This array is
155 /// defined in the generated ...Constants interface.
156 /// </summary>
157 public System.String[] tokenImage;
159 /// <summary> The end of line string for this machine.</summary>
160 protected internal System.String eol = SupportClass.AppSettings.Get("line.separator", "\n");
162 /// <summary> Used to convert raw characters to their escaped version
163 /// when these raw version cannot be used as part of an ASCII
164 /// string literal.
165 /// </summary>
166 protected internal virtual System.String Add_escapes(System.String str)
168 System.Text.StringBuilder retval = new System.Text.StringBuilder();
169 char ch;
170 for (int i = 0; i < str.Length; i++)
172 switch (str[i])
175 case (char) (0):
176 continue;
178 case '\b':
179 retval.Append("\\b");
180 continue;
182 case '\t':
183 retval.Append("\\t");
184 continue;
186 case '\n':
187 retval.Append("\\n");
188 continue;
190 case '\f':
191 retval.Append("\\f");
192 continue;
194 case '\r':
195 retval.Append("\\r");
196 continue;
198 case '\"':
199 retval.Append("\\\"");
200 continue;
202 case '\'':
203 retval.Append("\\\'");
204 continue;
206 case '\\':
207 retval.Append("\\\\");
208 continue;
210 default:
211 if ((ch = str[i]) < 0x20 || ch > 0x7e)
213 System.String s = "0000" + System.Convert.ToString(ch, 16);
214 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
216 else
218 retval.Append(ch);
220 continue;
224 return retval.ToString();