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