001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019 020package lucee.runtime.sql.old; 021 022 023public final class TokenMgrError extends Error 024{ 025 026 protected static final String addEscapes(String s) 027 { 028 StringBuffer stringbuffer = new StringBuffer(); 029 for(int i = 0; i < s.length(); i++) 030 { 031 char c; 032 switch(s.charAt(i)) 033 { 034 case 0: // '\0' 035 break; 036 037 case 8: // '\b' 038 stringbuffer.append("\\b"); 039 break; 040 041 case 9: // '\t' 042 stringbuffer.append("\\t"); 043 break; 044 045 case 10: // '\n' 046 stringbuffer.append("\\n"); 047 break; 048 049 case 12: // '\f' 050 stringbuffer.append("\\f"); 051 break; 052 053 case 13: // '\r' 054 stringbuffer.append("\\r"); 055 break; 056 057 case 34: // '"' 058 stringbuffer.append("\\\""); 059 break; 060 061 case 39: // '\'' 062 stringbuffer.append("\\'"); 063 break; 064 065 case 92: // '\\' 066 stringbuffer.append("\\\\"); 067 break; 068 069 default: 070 if((c = s.charAt(i)) < ' ' || c > '~') 071 { 072 String s1 = "0000" + Integer.toString(c, 16); 073 stringbuffer.append("\\u" + s1.substring(s1.length() - 4, s1.length())); 074 } else 075 { 076 stringbuffer.append(c); 077 } 078 break; 079 } 080 } 081 082 return stringbuffer.toString(); 083 } 084 085 private static final String LexicalError(boolean flag, int i, int j, int k, String s, char c) 086 { 087 return "Lexical error at line " + j + ", column " + k + ". Encountered: " + (flag ? "<EOF> " : "\"" + addEscapes(String.valueOf(c)) + "\"" + " (" + (int)c + "), ") + "after : \"" + addEscapes(s) + "\""; 088 } 089 090 public String getMessage() 091 { 092 return super.getMessage(); 093 } 094 095 public TokenMgrError() 096 { 097 } 098 099 public TokenMgrError(String s, int i) 100 { 101 super(s); 102 errorCode = i; 103 } 104 105 public TokenMgrError(boolean flag, int i, int j, int k, String s, char c, int l) 106 { 107 this(LexicalError(flag, i, j, k, s, c), l); 108 } 109 110 static final int LEXICAL_ERROR = 0; 111 static final int STATIC_LEXER_ERROR = 1; 112 static final int INVALID_LEXICAL_STATE = 2; 113 static final int LOOP_DETECTED = 3; 114 int errorCode; 115}