Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
TokenMgrError.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. TokenMgrError.java Version 3.0 */
19 
20 using System;
21 
22 namespace Lucene.Net.Demo.Html
23 {
24 
25  [Serializable]
26  public class TokenMgrError:System.ApplicationException
27  {
28  /// <summary> You can also modify the body of this method to customize your error messages.
29  /// For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
30  /// of end-users concern, so you can return something like :
31  ///
32  /// "Internal Error : Please file a bug report .... "
33  ///
34  /// from this method for such cases in the release version of your parser.
35  /// </summary>
36  public override System.String Message
37  {
38  get
39  {
40  return base.Message;
41  }
42 
43  }
44  /*
45  * Ordinals for various reasons why an Error of this type can be thrown.
46  */
47 
48  /// <summary> Lexical error occured.</summary>
49  internal const int LEXICAL_ERROR = 0;
50 
51  /// <summary> An attempt wass made to create a second instance of a static token manager.</summary>
52  internal const int STATIC_LEXER_ERROR = 1;
53 
54  /// <summary> Tried to change to an invalid lexical state.</summary>
55  internal const int INVALID_LEXICAL_STATE = 2;
56 
57  /// <summary> Detected (and bailed out of) an infinite loop in the token manager.</summary>
58  internal const int LOOP_DETECTED = 3;
59 
60  /// <summary> Indicates the reason why the exception is thrown. It will have
61  /// one of the above 4 values.
62  /// </summary>
63  internal int errorCode;
64 
65  /// <summary> Replaces unprintable characters by their espaced (or unicode escaped)
66  /// equivalents in the given string
67  /// </summary>
68  protected internal static System.String addEscapes(System.String str)
69  {
70  System.Text.StringBuilder retval = new System.Text.StringBuilder();
71  char ch;
72  for (int i = 0; i < str.Length; i++)
73  {
74  switch (str[i])
75  {
76 
77  case (char) (0):
78  continue;
79 
80  case '\b':
81  retval.Append("\\b");
82  continue;
83 
84  case '\t':
85  retval.Append("\\t");
86  continue;
87 
88  case '\n':
89  retval.Append("\\n");
90  continue;
91 
92  case '\f':
93  retval.Append("\\f");
94  continue;
95 
96  case '\r':
97  retval.Append("\\r");
98  continue;
99 
100  case '\"':
101  retval.Append("\\\"");
102  continue;
103 
104  case '\'':
105  retval.Append("\\\'");
106  continue;
107 
108  case '\\':
109  retval.Append("\\\\");
110  continue;
111 
112  default:
113  if ((ch = str[i]) < 0x20 || ch > 0x7e)
114  {
115  System.String s = "0000" + System.Convert.ToString(ch, 16);
116  retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
117  }
118  else
119  {
120  retval.Append(ch);
121  }
122  continue;
123 
124  }
125  }
126  return retval.ToString();
127  }
128 
129  /// <summary> Returns a detailed message for the Error when it is thrown by the
130  /// token manager to indicate a lexical error.
131  /// Parameters :
132  /// EOFSeen : indicates if EOF caused the lexicl error
133  /// curLexState : lexical state in which this error occured
134  /// errorLine : line number when the error occured
135  /// errorColumn : column number when the error occured
136  /// errorAfter : prefix that was seen before this error occured
137  /// curchar : the offending character
138  /// Note: You can customize the lexical error message by modifying this method.
139  /// </summary>
140  protected internal static System.String LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, System.String errorAfter, char curChar)
141  {
142  return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen?"<EOF> ":("\"" + addEscapes(System.Convert.ToString(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
143  }
144 
145  /*
146  * Constructors of various flavors follow.
147  */
148 
149  public TokenMgrError()
150  {
151  }
152 
153  public TokenMgrError(System.String message, int reason):base(message)
154  {
155  errorCode = reason;
156  }
157 
158  public TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, System.String errorAfter, char curChar, int reason):this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason)
159  {
160  }
161  }
162 }