2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
19 /* JavaCCOptions:KEEP_LINE_COL=null */
23 namespace Mono.Lucene.Net.QueryParsers
26 /// <summary> This exception is thrown when parse errors are encountered.
27 /// You can explicitly create objects of this exception type by
28 /// calling the method generateParseException in the generated
31 /// You can modify this class to customize your error reporting
32 /// mechanisms so long as you retain the public fields.
35 public class ParseException:System.Exception
37 /// <summary> This method has the standard behavior when this object has been
38 /// created using the standard constructors. Otherwise, it uses
39 /// "currentToken" and "expectedTokenSequences" to generate a parse
40 /// error message and returns it. If this object has been created
41 /// due to a parse error, and you do not catch it (it gets thrown
42 /// from the parser), then this method is called during the printing
43 /// of the final stack trace, and hence the correct error message
46 public override System.String Message
50 if (!specialConstructor)
54 System.Text.StringBuilder expected = new System.Text.StringBuilder();
56 for (int i = 0; i < expectedTokenSequences.Length; i++)
58 if (maxSize < expectedTokenSequences[i].Length)
60 maxSize = expectedTokenSequences[i].Length;
62 for (int j = 0; j < expectedTokenSequences[i].Length; j++)
64 expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
66 if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
68 expected.Append("...");
70 expected.Append(eol).Append(" ");
72 System.String retval = "Encountered \"";
73 Token tok = currentToken.next;
74 for (int i = 0; i < maxSize; i++)
80 retval += tokenImage[0];
83 retval += (" " + tokenImage[tok.kind]);
85 retval += Add_escapes(tok.image);
89 retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
90 retval += ("." + eol);
91 if (expectedTokenSequences.Length == 1)
93 retval += ("Was expecting:" + eol + " ");
97 retval += ("Was expecting one of:" + eol + " ");
99 retval += expected.ToString();
105 /// <summary> This constructor is used by the method "generateParseException"
106 /// in the generated parser. Calling this constructor generates
107 /// a new object of this type with the fields "currentToken",
108 /// "expectedTokenSequences", and "tokenImage" set. The boolean
109 /// flag "specialConstructor" is also set to true to indicate that
110 /// this constructor was used to create this object.
111 /// This constructor calls its super class with the empty string
112 /// to force the "toString" method of parent class "Throwable" to
113 /// print the error message in the form:
114 /// ParseException: <result of getMessage>
116 public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
118 specialConstructor = true;
119 currentToken = currentTokenVal;
120 expectedTokenSequences = expectedTokenSequencesVal;
121 tokenImage = tokenImageVal;
124 /// <summary> The following constructors are for use by you for whatever
125 /// purpose you can think of. Constructing the exception in this
126 /// manner makes the exception behave in the normal way - i.e., as
127 /// documented in the class "Throwable". The fields "errorToken",
128 /// "expectedTokenSequences", and "tokenImage" do not contain
129 /// relevant information. The JavaCC generated code does not use
130 /// these constructors.
133 public ParseException():base()
135 specialConstructor = false;
138 /// <summary>Constructor with message. </summary>
139 public ParseException(System.String message):base(message)
141 specialConstructor = false;
144 /// <summary>Constructor with message. </summary>
145 public ParseException(System.String message, System.Exception ex) : base(message, ex)
147 specialConstructor = false;
150 /// <summary> This variable determines which constructor was used to create
151 /// this object and thereby affects the semantics of the
152 /// "getMessage" method (see below).
154 protected internal bool specialConstructor;
156 /// <summary> This is the last token that has been consumed successfully. If
157 /// this object has been created due to a parse error, the token
158 /// followng this token will (therefore) be the first error token.
160 public Token currentToken;
162 /// <summary> Each entry in this array is an array of integers. Each array
163 /// of integers represents a sequence of tokens (by their ordinal
164 /// values) that is expected at this point of the parse.
166 public int[][] expectedTokenSequences;
168 /// <summary> This is a reference to the "tokenImage" array of the generated
169 /// parser within which the parse error occurred. This array is
170 /// defined in the generated ...Constants interface.
172 public System.String[] tokenImage;
174 /// <summary> The end of line string for this machine.</summary>
175 protected internal System.String eol = SupportClass.AppSettings.Get("line.separator", "\n");
177 /// <summary> Used to convert raw characters to their escaped version
178 /// when these raw version cannot be used as part of an ASCII
181 protected internal virtual System.String Add_escapes(System.String str)
183 System.Text.StringBuilder retval = new System.Text.StringBuilder();
185 for (int i = 0; i < str.Length; i++)
194 retval.Append("\\b");
198 retval.Append("\\t");
202 retval.Append("\\n");
206 retval.Append("\\f");
210 retval.Append("\\r");
214 retval.Append("\\\"");
218 retval.Append("\\\'");
222 retval.Append("\\\\");
226 if ((ch = str[i]) < 0x20 || ch > 0x7e)
228 System.String s = "0000" + System.Convert.ToString(ch, 16);
229 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
239 return retval.ToString();
242 /* JavaCC - OriginalChecksum=c63b396885c4ff44d7aa48d3feae60cd (do not edit this line) */