2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 */
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
26 /// You can modify this class to customize your error reporting
27 /// mechanisms so long as you retain the public fields.
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
41 public override System
.String Message
45 if (!specialConstructor
)
49 System
.String expected
= "";
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)
65 expected
+= (eol
+ " ");
67 System
.String retval
= "Encountered \"";
68 Token tok
= currentToken
.next
;
69 for (int i
= 0; i
< maxSize
; i
++)
75 retval
+= tokenImage
[0];
78 retval
+= Add_escapes(tok
.image
);
81 retval
+= ("\" at line " + currentToken
.next
.beginLine
+ ", column " + currentToken
.next
.beginColumn
+ "." + eol
);
82 if (expectedTokenSequences
.Length
== 1)
84 retval
+= ("Was expecting:" + eol
+ " ");
88 retval
+= ("Was expecting one of:" + eol
+ " ");
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: <result of getMessage>
107 public ParseException(Token currentTokenVal
, int[][] expectedTokenSequencesVal
, System
.String
[] tokenImageVal
) : base("")
109 eol
= System
.Configuration
.ConfigurationSettings
.AppSettings
.Get("line.separator");
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.
129 public ParseException() : base()
131 eol
= System
.Configuration
.ConfigurationSettings
.AppSettings
.Get("line.separator");
137 specialConstructor
= false;
140 public ParseException(System
.String message
) : base(message
)
142 eol
= System
.Configuration
.ConfigurationSettings
.AppSettings
.Get("line.separator");
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).
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.
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.
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.
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
182 protected internal virtual System
.String
Add_escapes(System
.String str
)
184 System
.Text
.StringBuilder retval
= new System
.Text
.StringBuilder();
186 for (int i
= 0; i
< str
.Length
; i
++)
195 retval
.Append("\\b");
199 retval
.Append("\\t");
203 retval
.Append("\\n");
207 retval
.Append("\\f");
211 retval
.Append("\\r");
215 retval
.Append("\\\"");
219 retval
.Append("\\\'");
223 retval
.Append("\\\\");
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)));
240 return retval
.ToString();