Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / Standard / TokenMgrError.cs
blob57a80845986960d12f4da1e77ccff5e6f0b96d1e
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
17 using System;
18 namespace Lucene.Net.Analysis.Standard
21 [Serializable]
22 public class TokenMgrError:System.ApplicationException
24 /// <summary> You can also modify the body of this method to customize your error messages.
25 /// For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
26 /// of end-users concern, so you can return something like :
27 ///
28 /// "Internal Error : Please file a bug report .... "
29 ///
30 /// from this method for such cases in the release version of your parser.
31 /// </summary>
32 public override System.String Message
34 get
36 return base.Message;
41 * Ordinals for various reasons why an Error of this type can be thrown.
44 /// <summary> Lexical error occured.</summary>
45 internal const int LEXICAL_ERROR = 0;
47 /// <summary> An attempt wass made to create a second instance of a static token manager.</summary>
48 internal const int STATIC_LEXER_ERROR = 1;
50 /// <summary> Tried to change to an invalid lexical state.</summary>
51 internal const int INVALID_LEXICAL_STATE = 2;
53 /// <summary> Detected (and bailed out of) an infinite loop in the token manager.</summary>
54 internal const int LOOP_DETECTED = 3;
56 /// <summary> Indicates the reason why the exception is thrown. It will have
57 /// one of the above 4 values.
58 /// </summary>
59 internal int errorCode;
61 /// <summary> Replaces unprintable characters by their espaced (or unicode escaped)
62 /// equivalents in the given string
63 /// </summary>
64 protected internal static System.String addEscapes(System.String str)
66 System.Text.StringBuilder retval = new System.Text.StringBuilder();
67 char ch;
68 for (int i = 0; i < str.Length; i++)
70 switch (str[i])
73 case (char) (0):
74 continue;
76 case '\b':
77 retval.Append("\\b");
78 continue;
80 case '\t':
81 retval.Append("\\t");
82 continue;
84 case '\n':
85 retval.Append("\\n");
86 continue;
88 case '\f':
89 retval.Append("\\f");
90 continue;
92 case '\r':
93 retval.Append("\\r");
94 continue;
96 case '\"':
97 retval.Append("\\\"");
98 continue;
100 case '\'':
101 retval.Append("\\\'");
102 continue;
104 case '\\':
105 retval.Append("\\\\");
106 continue;
108 default:
109 if ((ch = str[i]) < 0x20 || ch > 0x7e)
111 System.String s = "0000" + System.Convert.ToString(ch, 16);
112 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
114 else
116 retval.Append(ch);
118 continue;
122 return retval.ToString();
125 /// <summary> Returns a detailed message for the Error when it is thrown by the
126 /// token manager to indicate a lexical error.
127 /// Parameters :
128 /// EOFSeen : indicates if EOF caused the lexicl error
129 /// curLexState : lexical state in which this error occured
130 /// errorLine : line number when the error occured
131 /// errorColumn : column number when the error occured
132 /// errorAfter : prefix that was seen before this error occured
133 /// curchar : the offending character
134 /// Note: You can customize the lexical error message by modifying this method.
135 /// </summary>
136 protected internal static System.String LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, System.String errorAfter, char curChar)
138 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen?"<EOF> ":("\"" + addEscapes(System.Convert.ToString(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
142 * Constructors of various flavors follow.
145 public TokenMgrError()
149 public TokenMgrError(System.String message, int reason):base(message)
151 errorCode = reason;
154 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)