001 /** 002 * ========================================= 003 * LibFormula : a free Java formula library 004 * ========================================= 005 * 006 * Project Info: http://reporting.pentaho.org/libformula/ 007 * 008 * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors. 009 * 010 * This library is free software; you can redistribute it and/or modify it under the terms 011 * of the GNU Lesser General Public License as published by the Free Software Foundation; 012 * either version 2.1 of the License, or (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public License along with this 019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307, USA. 021 * 022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 023 * in the United States and other countries.] 024 * 025 * 026 * ------------ 027 * $Id: TokenMgrError.java 3521 2007-10-16 10:55:14Z tmorgner $ 028 * ------------ 029 * (C) Copyright 2006-2007, by Pentaho Corporation. 030 */ 031 032 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ 033 package org.jfree.formula.parser; 034 035 public class TokenMgrError extends Error 036 { 037 /* 038 * Ordinals for various reasons why an Error of this type can be thrown. 039 */ 040 041 /** 042 * Lexical error occured. 043 */ 044 static final int LEXICAL_ERROR = 0; 045 046 /** 047 * An attempt wass made to create a second instance of a static token manager. 048 */ 049 static final int STATIC_LEXER_ERROR = 1; 050 051 /** 052 * Tried to change to an invalid lexical state. 053 */ 054 static final int INVALID_LEXICAL_STATE = 2; 055 056 /** 057 * Detected (and bailed out of) an infinite loop in the token manager. 058 */ 059 static final int LOOP_DETECTED = 3; 060 061 /** 062 * Indicates the reason why the exception is thrown. It will have 063 * one of the above 4 values. 064 */ 065 int errorCode; 066 067 /** 068 * Replaces unprintable characters by their espaced (or unicode escaped) 069 * equivalents in the given string 070 */ 071 protected static String addEscapes(final String str) { 072 final StringBuffer retval = new StringBuffer(); 073 for (int i = 0; i < str.length(); i++) { 074 char ch; 075 switch (str.charAt(i)) 076 { 077 case 0 : 078 continue; 079 case '\b': 080 retval.append("\\b"); 081 continue; 082 case '\t': 083 retval.append("\\t"); 084 continue; 085 case '\n': 086 retval.append("\\n"); 087 continue; 088 case '\f': 089 retval.append("\\f"); 090 continue; 091 case '\r': 092 retval.append("\\r"); 093 continue; 094 case '\"': 095 retval.append("\\\""); 096 continue; 097 case '\'': 098 retval.append("\\\'"); 099 continue; 100 case '\\': 101 retval.append("\\\\"); 102 continue; 103 default: 104 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 105 final String s = "0000" + Integer.toString(ch, 16); 106 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 107 } else { 108 retval.append(ch); 109 } 110 continue; 111 } 112 } 113 return retval.toString(); 114 } 115 116 /** 117 * Returns a detailed message for the Error when it is thrown by the 118 * token manager to indicate a lexical error. 119 * Parameters : 120 * EOFSeen : indicates if EOF caused the lexicl error 121 * curLexState : lexical state in which this error occured 122 * errorLine : line number when the error occured 123 * errorColumn : column number when the error occured 124 * errorAfter : prefix that was seen before this error occured 125 * curchar : the offending character 126 * Note: You can customize the lexical error message by modifying this method. 127 */ 128 protected static String LexicalError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final char curChar) { 129 return("Lexical error at line " + 130 errorLine + ", column " + 131 errorColumn + ". Encountered: " + 132 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 133 "after : \"" + addEscapes(errorAfter) + "\""); 134 } 135 136 /** 137 * You can also modify the body of this method to customize your error messages. 138 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 139 * of end-users concern, so you can return something like : 140 * 141 * "Internal Error : Please file a bug report .... " 142 * 143 * from this method for such cases in the release version of your parser. 144 */ 145 public String getMessage() { 146 return super.getMessage(); 147 } 148 149 /* 150 * Constructors of various flavors follow. 151 */ 152 153 public TokenMgrError() { 154 } 155 156 public TokenMgrError(final String message, final int reason) { 157 super(message); 158 errorCode = reason; 159 } 160 161 public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final char curChar, final int reason) { 162 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 163 } 164 }