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.
17 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
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
27 /// You can modify this class to customize your error reporting
28 /// mechanisms so long as you retain the public fields.
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
42 public override System
.String Message
46 if (!specialConstructor
)
50 System
.String expected
= "";
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)
66 expected
+= (eol
+ " ");
68 System
.String retval
= "Encountered \"";
69 Token tok
= currentToken
.next
;
70 for (int i
= 0; i
< maxSize
; i
++)
76 retval
+= tokenImage
[0];
79 retval
+= Add_escapes(tok
.image
);
82 retval
+= ("\" at line " + currentToken
.next
.beginLine
+ ", column " + currentToken
.next
.beginColumn
+ "." + eol
);
83 if (expectedTokenSequences
.Length
== 1)
85 retval
+= ("Was expecting:" + eol
+ " ");
89 retval
+= ("Was expecting one of:" + eol
+ " ");
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>
108 public ParseException(Token currentTokenVal
, int[][] expectedTokenSequencesVal
, System
.String
[] tokenImageVal
):base("")
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.
127 public ParseException() : base()
131 specialConstructor
= false;
134 public ParseException(System
.String message
) : base(message
)
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).
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.
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.
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.
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
172 protected internal virtual System
.String
Add_escapes(System
.String str
)
174 System
.Text
.StringBuilder retval
= new System
.Text
.StringBuilder();
176 for (int i
= 0; i
< str
.Length
; i
++)
185 retval
.Append("\\b");
189 retval
.Append("\\t");
193 retval
.Append("\\n");
197 retval
.Append("\\f");
201 retval
.Append("\\r");
205 retval
.Append("\\\"");
209 retval
.Append("\\\'");
213 retval
.Append("\\\\");
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)));
230 return retval
.ToString();