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 3.0 */
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
29 /// You can modify this class to customize your error reporting
30 /// mechanisms so long as you retain the public fields.
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
44 public override System
.String Message
48 if (!specialConstructor
)
52 System
.String expected
= "";
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)
68 expected
+= (eol
+ " ");
70 System
.String retval
= "Encountered \"";
71 Token tok
= currentToken
.next
;
72 for (int i
= 0; i
< maxSize
; i
++)
78 retval
+= tokenImage
[0];
81 retval
+= Add_escapes(tok
.image
);
84 retval
+= ("\" at line " + currentToken
.next
.beginLine
+ ", column " + currentToken
.next
.beginColumn
);
85 retval
+= ("." + eol
);
86 if (expectedTokenSequences
.Length
== 1)
88 retval
+= ("Was expecting:" + eol
+ " ");
92 retval
+= ("Was expecting one of:" + eol
+ " ");
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>
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.
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).
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.
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.
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.
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
169 protected internal virtual System
.String
Add_escapes(System
.String str
)
171 System
.Text
.StringBuilder retval
= new System
.Text
.StringBuilder();
173 for (int i
= 0; i
< str
.Length
; i
++)
182 retval
.Append("\\b");
186 retval
.Append("\\t");
190 retval
.Append("\\n");
194 retval
.Append("\\f");
198 retval
.Append("\\r");
202 retval
.Append("\\\"");
206 retval
.Append("\\\'");
210 retval
.Append("\\\\");
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)));
227 return retval
.ToString();