Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
ParseException.cs
Go to the documentation of this file.
1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
19 /* JavaCCOptions:KEEP_LINE_COL=null */
20 
21 using System;
22 using Lucene.Net.Support;
23 
24 namespace Lucene.Net.QueryParsers
25 {
26 
35  [Serializable]
36  public class ParseException:System.Exception
37  {
47  public override System.String Message
48  {
49  get
50  {
51  if (!specialConstructor)
52  {
53  return base.Message;
54  }
55  System.Text.StringBuilder expected = new System.Text.StringBuilder();
56  int maxSize = 0;
57  for (int i = 0; i < expectedTokenSequences.Length; i++)
58  {
59  if (maxSize < expectedTokenSequences[i].Length)
60  {
61  maxSize = expectedTokenSequences[i].Length;
62  }
63  for (int j = 0; j < expectedTokenSequences[i].Length; j++)
64  {
65  expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
66  }
67  if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
68  {
69  expected.Append("...");
70  }
71  expected.Append(eol).Append(" ");
72  }
73  System.String retval = "Encountered \"";
74  Token tok = currentToken.next;
75  for (int i = 0; i < maxSize; i++)
76  {
77  if (i != 0)
78  retval += " ";
79  if (tok.kind == 0)
80  {
81  retval += tokenImage[0];
82  break;
83  }
84  retval += (" " + tokenImage[tok.kind]);
85  retval += " \"";
86  retval += Add_escapes(tok.image);
87  retval += " \"";
88  tok = tok.next;
89  }
90  retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
91  retval += ("." + eol);
92  if (expectedTokenSequences.Length == 1)
93  {
94  retval += ("Was expecting:" + eol + " ");
95  }
96  else
97  {
98  retval += ("Was expecting one of:" + eol + " ");
99  }
100  retval += expected.ToString();
101  return retval;
102  }
103 
104  }
105 
117  public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
118  {
119  specialConstructor = true;
120  currentToken = currentTokenVal;
121  expectedTokenSequences = expectedTokenSequencesVal;
122  tokenImage = tokenImageVal;
123  }
124 
133 
134  public ParseException():base()
135  {
136  specialConstructor = false;
137  }
138 
140  public ParseException(System.String message):base(message)
141  {
142  specialConstructor = false;
143  }
144 
146  public ParseException(System.String message, System.Exception ex) : base(message, ex)
147  {
148  specialConstructor = false;
149  }
150 
155  protected internal bool specialConstructor;
156 
162 
167  public int[][] expectedTokenSequences;
168 
173  public System.String[] tokenImage;
174 
176  protected internal System.String eol = AppSettings.Get("line.separator", "\n");
177 
182  protected internal virtual System.String Add_escapes(System.String str)
183  {
184  System.Text.StringBuilder retval = new System.Text.StringBuilder();
185  char ch;
186  for (int i = 0; i < str.Length; i++)
187  {
188  switch (str[i])
189  {
190 
191  case (char) (0):
192  continue;
193 
194  case '\b':
195  retval.Append("\\b");
196  continue;
197 
198  case '\t':
199  retval.Append("\\t");
200  continue;
201 
202  case '\n':
203  retval.Append("\\n");
204  continue;
205 
206  case '\f':
207  retval.Append("\\f");
208  continue;
209 
210  case '\r':
211  retval.Append("\\r");
212  continue;
213 
214  case '\"':
215  retval.Append("\\\"");
216  continue;
217 
218  case '\'':
219  retval.Append("\\\'");
220  continue;
221 
222  case '\\':
223  retval.Append("\\\\");
224  continue;
225 
226  default:
227  if ((ch = str[i]) < 0x20 || ch > 0x7e)
228  {
229  System.String s = "0000" + System.Convert.ToString(ch, 16);
230  retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
231  }
232  else
233  {
234  retval.Append(ch);
235  }
236  continue;
237 
238  }
239  }
240  return retval.ToString();
241  }
242  }
243  /* JavaCC - OriginalChecksum=c7631a240f7446940695eac31d9483ca (do not edit this line) */
244 }