cvsimport
[beagle.git] / beagled / Lucene.Net / Analysis / Standard / ParseException.cs
blobbac8ea32d42b00b4a80e242a46f8ade107a30c7e
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 0.7pre6 */
18 using System;
19 namespace Lucene.Net.Analysis.Standard
22 /// <summary> This exception is thrown when parse errors are encountered.
23 /// You can explicitly create objects of this exception type by
24 /// calling the method generateParseException in the generated
25 /// parser.
26 ///
27 /// You can modify this class to customize your error reporting
28 /// mechanisms so long as you retain the public fields.
29 /// </summary>
30 [Serializable]
31 public class ParseException : System.IO.IOException
33 /// <summary> This method has the standard behavior when this object has been
34 /// created using the standard constructors. Otherwise, it uses
35 /// "currentToken" and "expectedTokenSequences" to generate a parse
36 /// error message and returns it. If this object has been created
37 /// due to a parse error, and you do not catch it (it gets thrown
38 /// from the parser), then this method is called during the printing
39 /// of the final stack trace, and hence the correct error message
40 /// gets displayed.
41 /// </summary>
42 public override System.String Message
44 get
46 if (!specialConstructor)
48 return base.Message;
50 System.String expected = "";
51 int maxSize = 0;
52 for (int i = 0; i < expectedTokenSequences.Length; i++)
54 if (maxSize < expectedTokenSequences[i].Length)
56 maxSize = expectedTokenSequences[i].Length;
58 for (int j = 0; j < expectedTokenSequences[i].Length; j++)
60 expected += (tokenImage[expectedTokenSequences[i][j]] + " ");
62 if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
64 expected += "...";
66 expected += (eol + " ");
68 System.String retval = "Encountered \"";
69 Token tok = currentToken.next;
70 for (int i = 0; i < maxSize; i++)
72 if (i != 0)
73 retval += " ";
74 if (tok.kind == 0)
76 retval += tokenImage[0];
77 break;
79 retval += Add_escapes(tok.image);
80 tok = tok.next;
82 retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + 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: &lt;result of getMessage&gt;
107 /// </summary>
108 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
110 if (eol == null)
111 eol = @"\n";
112 specialConstructor = true;
113 currentToken = currentTokenVal;
114 expectedTokenSequences = expectedTokenSequencesVal;
115 tokenImage = tokenImageVal;
118 /// <summary> The following constructors are for use by you for whatever
119 /// purpose you can think of. Constructing the exception in this
120 /// manner makes the exception behave in the normal way - i.e., as
121 /// documented in the class "Throwable". The fields "errorToken",
122 /// "expectedTokenSequences", and "tokenImage" do not contain
123 /// relevant information. The JavaCC generated code does not use
124 /// these constructors.
125 /// </summary>
127 public ParseException() : base()
129 if (eol == null)
130 eol = @"\n";
131 specialConstructor = false;
134 public ParseException(System.String message) : base(message)
136 if (eol == null)
137 eol = @"\n";
138 specialConstructor = false;
141 /// <summary> This variable determines which constructor was used to create
142 /// this object and thereby affects the semantics of the
143 /// "getMessage" method (see below).
144 /// </summary>
145 protected internal bool specialConstructor;
147 /// <summary> This is the last token that has been consumed successfully. If
148 /// this object has been created due to a parse error, the token
149 /// followng this token will (therefore) be the first error token.
150 /// </summary>
151 public Token currentToken;
153 /// <summary> Each entry in this array is an array of integers. Each array
154 /// of integers represents a sequence of tokens (by their ordinal
155 /// values) that is expected at this point of the parse.
156 /// </summary>
157 public int[][] expectedTokenSequences;
159 /// <summary> This is a reference to the "tokenImage" array of the generated
160 /// parser within which the parse error occurred. This array is
161 /// defined in the generated ...Constants interface.
162 /// </summary>
163 public System.String[] tokenImage;
165 /// <summary> The end of line string for this machine.</summary>
166 protected internal System.String eol = System.Configuration.ConfigurationSettings.AppSettings.Get("line.separator");
168 /// <summary> Used to convert raw characters to their escaped version
169 /// when these raw version cannot be used as part of an ASCII
170 /// string literal.
171 /// </summary>
172 protected internal virtual System.String Add_escapes(System.String str)
174 System.Text.StringBuilder retval = new System.Text.StringBuilder();
175 char ch;
176 for (int i = 0; i < str.Length; i++)
178 switch (str[i])
181 case (char) (0):
182 continue;
184 case '\b':
185 retval.Append("\\b");
186 continue;
188 case '\t':
189 retval.Append("\\t");
190 continue;
192 case '\n':
193 retval.Append("\\n");
194 continue;
196 case '\f':
197 retval.Append("\\f");
198 continue;
200 case '\r':
201 retval.Append("\\r");
202 continue;
204 case '\"':
205 retval.Append("\\\"");
206 continue;
208 case '\'':
209 retval.Append("\\\'");
210 continue;
212 case '\\':
213 retval.Append("\\\\");
214 continue;
216 default:
217 if ((ch = str[i]) < 0x20 || ch > 0x7e)
219 System.String s = "0000" + System.Convert.ToString(ch, 16);
220 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
222 else
224 retval.Append(ch);
226 continue;
230 return retval.ToString();