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