cvsimport
[beagle.git] / beagled / Lucene.Net / QueryParser / ParseException.cs
blobe496452194e0866a67c3b234e039ea4ec9709f59
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.
17 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
19 using System;
21 namespace Lucene.Net.QueryParsers
24 /// <summary> This exception is thrown when parse errors are encountered.
25 /// You can explicitly create objects of this exception type by
26 /// calling the method generateParseException in the generated
27 /// parser.
28 ///
29 /// You can modify this class to customize your error reporting
30 /// mechanisms so long as you retain the public fields.
31 /// </summary>
32 [Serializable]
33 public class ParseException : System.Exception
35 /// <summary> This method has the standard behavior when this object has been
36 /// created using the standard constructors. Otherwise, it uses
37 /// "currentToken" and "expectedTokenSequences" to generate a parse
38 /// error message and returns it. If this object has been created
39 /// due to a parse error, and you do not catch it (it gets thrown
40 /// from the parser), then this method is called during the printing
41 /// of the final stack trace, and hence the correct error message
42 /// gets displayed.
43 /// </summary>
44 public override System.String Message
46 get
48 if (!specialConstructor)
50 return base.Message;
52 System.String expected = "";
53 int maxSize = 0;
54 for (int i = 0; i < expectedTokenSequences.Length; i++)
56 if (maxSize < expectedTokenSequences[i].Length)
58 maxSize = expectedTokenSequences[i].Length;
60 for (int j = 0; j < expectedTokenSequences[i].Length; j++)
62 expected += (tokenImage[expectedTokenSequences[i][j]] + " ");
64 if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
66 expected += "...";
68 expected += (eol + " ");
70 System.String retval = "Encountered \"";
71 Token tok = currentToken.next;
72 for (int i = 0; i < maxSize; i++)
74 if (i != 0)
75 retval += " ";
76 if (tok.kind == 0)
78 retval += tokenImage[0];
79 break;
81 retval += Add_escapes(tok.image);
82 tok = tok.next;
84 retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
85 retval += ("." + eol);
86 if (expectedTokenSequences.Length == 1)
88 retval += ("Was expecting:" + eol + " ");
90 else
92 retval += ("Was expecting one of:" + eol + " ");
94 retval += expected;
95 return retval;
100 /// <summary> This constructor is used by the method "generateParseException"
101 /// in the generated parser. Calling this constructor generates
102 /// a new object of this type with the fields "currentToken",
103 /// "expectedTokenSequences", and "tokenImage" set. The boolean
104 /// flag "specialConstructor" is also set to true to indicate that
105 /// this constructor was used to create this object.
106 /// This constructor calls its super class with the empty string
107 /// to force the "toString" method of parent class "Throwable" to
108 /// print the error message in the form:
109 /// ParseException: <result of getMessage>
110 /// </summary>
111 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
113 specialConstructor = true;
114 currentToken = currentTokenVal;
115 expectedTokenSequences = expectedTokenSequencesVal;
116 tokenImage = tokenImageVal;
119 /// <summary> The following constructors are for use by you for whatever
120 /// purpose you can think of. Constructing the exception in this
121 /// manner makes the exception behave in the normal way - i.e., as
122 /// documented in the class "Throwable". The fields "errorToken",
123 /// "expectedTokenSequences", and "tokenImage" do not contain
124 /// relevant information. The JavaCC generated code does not use
125 /// these constructors.
126 /// </summary>
128 public ParseException():base()
130 specialConstructor = false;
133 public ParseException(System.String message) : base(message)
135 specialConstructor = false;
138 /// <summary> This variable determines which constructor was used to create
139 /// this object and thereby affects the semantics of the
140 /// "getMessage" method (see below).
141 /// </summary>
142 protected internal bool specialConstructor;
144 /// <summary> This is the last token that has been consumed successfully. If
145 /// this object has been created due to a parse error, the token
146 /// followng this token will (therefore) be the first error token.
147 /// </summary>
148 public Token currentToken;
150 /// <summary> Each entry in this array is an array of integers. Each array
151 /// of integers represents a sequence of tokens (by their ordinal
152 /// values) that is expected at this point of the parse.
153 /// </summary>
154 public int[][] expectedTokenSequences;
156 /// <summary> This is a reference to the "tokenImage" array of the generated
157 /// parser within which the parse error occurred. This array is
158 /// defined in the generated ...Constants interface.
159 /// </summary>
160 public System.String[] tokenImage;
162 /// <summary> The end of line string for this machine.</summary>
163 protected internal System.String eol = SupportClass.AppSettings.Get("line.separator", "\n");
165 /// <summary> Used to convert raw characters to their escaped version
166 /// when these raw version cannot be used as part of an ASCII
167 /// string literal.
168 /// </summary>
169 protected internal virtual System.String Add_escapes(System.String str)
171 System.Text.StringBuilder retval = new System.Text.StringBuilder();
172 char ch;
173 for (int i = 0; i < str.Length; i++)
175 switch (str[i])
178 case (char) (0):
179 continue;
181 case '\b':
182 retval.Append("\\b");
183 continue;
185 case '\t':
186 retval.Append("\\t");
187 continue;
189 case '\n':
190 retval.Append("\\n");
191 continue;
193 case '\f':
194 retval.Append("\\f");
195 continue;
197 case '\r':
198 retval.Append("\\r");
199 continue;
201 case '\"':
202 retval.Append("\\\"");
203 continue;
205 case '\'':
206 retval.Append("\\\'");
207 continue;
209 case '\\':
210 retval.Append("\\\\");
211 continue;
213 default:
214 if ((ch = str[i]) < 0x20 || ch > 0x7e)
216 System.String s = "0000" + System.Convert.ToString(ch, 16);
217 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
219 else
221 retval.Append(ch);
223 continue;
227 return retval.ToString();