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 3.0 */
19 
20 using System;
21 using Lucene.Net.Support;
22 
23 namespace Lucene.Net.Demo.Html
24 {
25 
34  [Serializable]
35  public class ParseException:System.Exception
36  {
46  public override System.String Message
47  {
48  get
49  {
50  if (!specialConstructor)
51  {
52  return base.Message;
53  }
54  System.Text.StringBuilder expected = new System.Text.StringBuilder();
55  int maxSize = 0;
56  for (int i = 0; i < expectedTokenSequences.Length; i++)
57  {
58  if (maxSize < expectedTokenSequences[i].Length)
59  {
60  maxSize = expectedTokenSequences[i].Length;
61  }
62  for (int j = 0; j < expectedTokenSequences[i].Length; j++)
63  {
64  expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(" ");
65  }
66  if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
67  {
68  expected.Append("...");
69  }
70  expected.Append(eol).Append(" ");
71  }
72  System.String retval = "Encountered \"";
73  Token tok = currentToken.next;
74  for (int i = 0; i < maxSize; i++)
75  {
76  if (i != 0)
77  retval += " ";
78  if (tok.kind == 0)
79  {
80  retval += tokenImage[0];
81  break;
82  }
83  retval += Add_escapes(tok.image);
84  tok = tok.next;
85  }
86  retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
87  retval += ("." + eol);
88  if (expectedTokenSequences.Length == 1)
89  {
90  retval += ("Was expecting:" + eol + " ");
91  }
92  else
93  {
94  retval += ("Was expecting one of:" + eol + " ");
95  }
96  retval += expected.ToString();
97  return retval;
98  }
99 
100  }
101 
113  public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, System.String[] tokenImageVal):base("")
114  {
115  specialConstructor = true;
116  currentToken = currentTokenVal;
117  expectedTokenSequences = expectedTokenSequencesVal;
118  tokenImage = tokenImageVal;
119  }
120 
129 
130  public ParseException():base()
131  {
132  specialConstructor = false;
133  }
134 
135  public ParseException(System.String message):base(message)
136  {
137  specialConstructor = false;
138  }
139 
144  protected internal bool specialConstructor;
145 
151 
156  public int[][] expectedTokenSequences;
157 
162  public System.String[] tokenImage;
163 
165  protected internal System.String eol = AppSettings.Get("line.separator", "\n");
166 
171  protected internal virtual System.String Add_escapes(System.String str)
172  {
173  System.Text.StringBuilder retval = new System.Text.StringBuilder();
174  char ch;
175  for (int i = 0; i < str.Length; i++)
176  {
177  switch (str[i])
178  {
179 
180  case (char) (0):
181  continue;
182 
183  case '\b':
184  retval.Append("\\b");
185  continue;
186 
187  case '\t':
188  retval.Append("\\t");
189  continue;
190 
191  case '\n':
192  retval.Append("\\n");
193  continue;
194 
195  case '\f':
196  retval.Append("\\f");
197  continue;
198 
199  case '\r':
200  retval.Append("\\r");
201  continue;
202 
203  case '\"':
204  retval.Append("\\\"");
205  continue;
206 
207  case '\'':
208  retval.Append("\\\'");
209  continue;
210 
211  case '\\':
212  retval.Append("\\\\");
213  continue;
214 
215  default:
216  if ((ch = str[i]) < 0x20 || ch > 0x7e)
217  {
218  System.String s = "0000" + System.Convert.ToString(ch, 16);
219  retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
220  }
221  else
222  {
223  retval.Append(ch);
224  }
225  continue;
226 
227  }
228  }
229  return retval.ToString();
230  }
231  }
232 }