cvsimport
[beagle.git] / beagled / Lucene.Net / QueryParser / TokenMgrError.cs
blob1514616c4eca0a80ce8153d8036d2da28e315cb2
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.
17 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
19 using System;
21 namespace Lucene.Net.QueryParsers
24 [Serializable]
25 public class TokenMgrError:System.ApplicationException
27 /// <summary> You can also modify the body of this method to customize your error messages.
28 /// For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
29 /// of end-users concern, so you can return something like :
30 ///
31 /// "Internal Error : Please file a bug report .... "
32 ///
33 /// from this method for such cases in the release version of your parser.
34 /// </summary>
35 public override System.String Message
37 get
39 return base.Message;
44 * Ordinals for various reasons why an Error of this type can be thrown.
47 /// <summary> Lexical error occured.</summary>
48 internal const int LEXICAL_ERROR = 0;
50 /// <summary> An attempt wass made to create a second instance of a static token manager.</summary>
51 internal const int STATIC_LEXER_ERROR = 1;
53 /// <summary> Tried to change to an invalid lexical state.</summary>
54 internal const int INVALID_LEXICAL_STATE = 2;
56 /// <summary> Detected (and bailed out of) an infinite loop in the token manager.</summary>
57 internal const int LOOP_DETECTED = 3;
59 /// <summary> Indicates the reason why the exception is thrown. It will have
60 /// one of the above 4 values.
61 /// </summary>
62 internal int errorCode;
64 /// <summary> Replaces unprintable characters by their espaced (or unicode escaped)
65 /// equivalents in the given string
66 /// </summary>
67 protected internal static System.String addEscapes(System.String str)
69 System.Text.StringBuilder retval = new System.Text.StringBuilder();
70 char ch;
71 for (int i = 0; i < str.Length; i++)
73 switch (str[i])
76 case (char) (0):
77 continue;
79 case '\b':
80 retval.Append("\\b");
81 continue;
83 case '\t':
84 retval.Append("\\t");
85 continue;
87 case '\n':
88 retval.Append("\\n");
89 continue;
91 case '\f':
92 retval.Append("\\f");
93 continue;
95 case '\r':
96 retval.Append("\\r");
97 continue;
99 case '\"':
100 retval.Append("\\\"");
101 continue;
103 case '\'':
104 retval.Append("\\\'");
105 continue;
107 case '\\':
108 retval.Append("\\\\");
109 continue;
111 default:
112 if ((ch = str[i]) < 0x20 || ch > 0x7e)
114 System.String s = "0000" + System.Convert.ToString(ch, 16);
115 retval.Append("\\u" + s.Substring(s.Length - 4, (s.Length) - (s.Length - 4)));
117 else
119 retval.Append(ch);
121 continue;
125 return retval.ToString();
128 /// <summary> Returns a detailed message for the Error when it is thrown by the
129 /// token manager to indicate a lexical error.
130 /// Parameters :
131 /// EOFSeen : indicates if EOF caused the lexicl error
132 /// curLexState : lexical state in which this error occured
133 /// errorLine : line number when the error occured
134 /// errorColumn : column number when the error occured
135 /// errorAfter : prefix that was seen before this error occured
136 /// curchar : the offending character
137 /// Note: You can customize the lexical error message by modifying this method.
138 /// </summary>
139 protected internal static System.String LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, System.String errorAfter, char curChar)
141 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen?"<EOF> ":("\"" + addEscapes(System.Convert.ToString(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
145 * Constructors of various flavors follow.
148 public TokenMgrError()
152 public TokenMgrError(System.String message, int reason):base(message)
154 errorCode = reason;
157 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)