001 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
002 /**
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 package org.apache.hadoop.record.compiler.generated;
021
022 import org.apache.hadoop.classification.InterfaceAudience;
023 import org.apache.hadoop.classification.InterfaceStability;
024
025 /**
026 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
027 */
028 @Deprecated
029 @InterfaceAudience.Public
030 @InterfaceStability.Stable
031 public class TokenMgrError extends Error
032 {
033 /*
034 * Ordinals for various reasons why an Error of this type can be thrown.
035 */
036
037 /**
038 * Lexical error occured.
039 */
040 static final int LEXICAL_ERROR = 0;
041
042 /**
043 * An attempt wass made to create a second instance of a static token manager.
044 */
045 static final int STATIC_LEXER_ERROR = 1;
046
047 /**
048 * Tried to change to an invalid lexical state.
049 */
050 static final int INVALID_LEXICAL_STATE = 2;
051
052 /**
053 * Detected (and bailed out of) an infinite loop in the token manager.
054 */
055 static final int LOOP_DETECTED = 3;
056
057 /**
058 * Indicates the reason why the exception is thrown. It will have
059 * one of the above 4 values.
060 */
061 int errorCode;
062
063 /**
064 * Replaces unprintable characters by their espaced (or unicode escaped)
065 * equivalents in the given string
066 */
067 protected static final String addEscapes(String str) {
068 StringBuffer retval = new StringBuffer();
069 char ch;
070 for (int i = 0; i < str.length(); i++) {
071 switch (str.charAt(i))
072 {
073 case 0 :
074 continue;
075 case '\b':
076 retval.append("\\b");
077 continue;
078 case '\t':
079 retval.append("\\t");
080 continue;
081 case '\n':
082 retval.append("\\n");
083 continue;
084 case '\f':
085 retval.append("\\f");
086 continue;
087 case '\r':
088 retval.append("\\r");
089 continue;
090 case '\"':
091 retval.append("\\\"");
092 continue;
093 case '\'':
094 retval.append("\\\'");
095 continue;
096 case '\\':
097 retval.append("\\\\");
098 continue;
099 default:
100 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
101 String s = "0000" + Integer.toString(ch, 16);
102 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
103 } else {
104 retval.append(ch);
105 }
106 continue;
107 }
108 }
109 return retval.toString();
110 }
111
112 /**
113 * Returns a detailed message for the Error when it is thrown by the
114 * token manager to indicate a lexical error.
115 * Parameters :
116 * EOFSeen : indicates if EOF caused the lexicl error
117 * curLexState : lexical state in which this error occured
118 * errorLine : line number when the error occured
119 * errorColumn : column number when the error occured
120 * errorAfter : prefix that was seen before this error occured
121 * curchar : the offending character
122 * Note: You can customize the lexical error message by modifying this method.
123 */
124 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
125 return("Lexical error at line " +
126 errorLine + ", column " +
127 errorColumn + ". Encountered: " +
128 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
129 "after : \"" + addEscapes(errorAfter) + "\"");
130 }
131
132 /**
133 * You can also modify the body of this method to customize your error messages.
134 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
135 * of end-users concern, so you can return something like :
136 *
137 * "Internal Error : Please file a bug report .... "
138 *
139 * from this method for such cases in the release version of your parser.
140 */
141 @Override
142 public String getMessage() {
143 return super.getMessage();
144 }
145
146 /*
147 * Constructors of various flavors follow.
148 */
149
150 public TokenMgrError() {
151 }
152
153 public TokenMgrError(String message, int reason) {
154 super(message);
155 errorCode = reason;
156 }
157
158 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
159 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
160 }
161 }