|
| 1 | +/** |
| 2 | + * Copyright (C) 2011 Akiban Technologies Inc. |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 5 | + * as published by the Free Software Foundation. |
| 6 | + * |
| 7 | + * This program is distributed in the hope that it will be useful, |
| 8 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + * GNU Affero General Public License for more details. |
| 11 | + * |
| 12 | + * You should have received a copy of the GNU Affero General Public License |
| 13 | + * along with this program. If not, see http://www.gnu.org/licenses. |
| 14 | + */ |
| 15 | + |
| 16 | +/* Derived from automatically generated file */ |
| 17 | + |
| 18 | +package com.akiban.sql.parser; |
| 19 | + |
| 20 | +/** Token Manager Error. */ |
| 21 | +class TokenMgrError extends Error |
| 22 | +{ |
| 23 | + /* |
| 24 | + * Ordinals for various reasons why an Error of this type can be thrown. |
| 25 | + */ |
| 26 | + |
| 27 | + /** |
| 28 | + * Lexical error occurred. |
| 29 | + */ |
| 30 | + static final int LEXICAL_ERROR = 0; |
| 31 | + |
| 32 | + /** |
| 33 | + * An attempt was made to create a second instance of a static token manager. |
| 34 | + */ |
| 35 | + static final int STATIC_LEXER_ERROR = 1; |
| 36 | + |
| 37 | + /** |
| 38 | + * Tried to change to an invalid lexical state. |
| 39 | + */ |
| 40 | + static final int INVALID_LEXICAL_STATE = 2; |
| 41 | + |
| 42 | + /** |
| 43 | + * Detected (and bailed out of) an infinite loop in the token manager. |
| 44 | + */ |
| 45 | + static final int LOOP_DETECTED = 3; |
| 46 | + |
| 47 | + /** |
| 48 | + * Indicates the reason why the exception is thrown. It will have |
| 49 | + * one of the above 4 values. |
| 50 | + */ |
| 51 | + int errorCode, errorLine, errorColumn; |
| 52 | + |
| 53 | + /** |
| 54 | + * Replaces unprintable characters by their escaped (or unicode escaped) |
| 55 | + * equivalents in the given string |
| 56 | + */ |
| 57 | + protected static final String addEscapes(String str) { |
| 58 | + StringBuffer retval = new StringBuffer(); |
| 59 | + char ch; |
| 60 | + for (int i = 0; i < str.length(); i++) { |
| 61 | + switch (str.charAt(i)) |
| 62 | + { |
| 63 | + case 0 : |
| 64 | + continue; |
| 65 | + case '\b': |
| 66 | + retval.append("\\b"); |
| 67 | + continue; |
| 68 | + case '\t': |
| 69 | + retval.append("\\t"); |
| 70 | + continue; |
| 71 | + case '\n': |
| 72 | + retval.append("\\n"); |
| 73 | + continue; |
| 74 | + case '\f': |
| 75 | + retval.append("\\f"); |
| 76 | + continue; |
| 77 | + case '\r': |
| 78 | + retval.append("\\r"); |
| 79 | + continue; |
| 80 | + case '\"': |
| 81 | + retval.append("\\\""); |
| 82 | + continue; |
| 83 | + case '\'': |
| 84 | + retval.append("\\\'"); |
| 85 | + continue; |
| 86 | + case '\\': |
| 87 | + retval.append("\\\\"); |
| 88 | + continue; |
| 89 | + default: |
| 90 | + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
| 91 | + String s = "0000" + Integer.toString(ch, 16); |
| 92 | + retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
| 93 | + } else { |
| 94 | + retval.append(ch); |
| 95 | + } |
| 96 | + continue; |
| 97 | + } |
| 98 | + } |
| 99 | + return retval.toString(); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Returns a detailed message for the Error when it is thrown by the |
| 104 | + * token manager to indicate a lexical error. |
| 105 | + * Parameters : |
| 106 | + * EOFSeen : indicates if EOF caused the lexical error |
| 107 | + * curLexState : lexical state in which this error occurred |
| 108 | + * errorLine : line number when the error occurred |
| 109 | + * errorColumn : column number when the error occurred |
| 110 | + * errorAfter : prefix that was seen before this error occurred |
| 111 | + * curchar : the offending character |
| 112 | + * Note: You can customize the lexical error message by modifying this method. |
| 113 | + */ |
| 114 | + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { |
| 115 | + return("Lexical error at line " + |
| 116 | + errorLine + ", column " + |
| 117 | + errorColumn + ". Encountered: " + |
| 118 | + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + |
| 119 | + "after : \"" + addEscapes(errorAfter) + "\""); |
| 120 | + } |
| 121 | + |
| 122 | + /* |
| 123 | + * Constructors of various flavors follow. |
| 124 | + */ |
| 125 | + |
| 126 | + /** Constructor with message and reason. */ |
| 127 | + public TokenMgrError(String message, int reason) { |
| 128 | + super(message); |
| 129 | + errorCode = reason; |
| 130 | + } |
| 131 | + |
| 132 | + /** Full Constructor. */ |
| 133 | + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { |
| 134 | + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
| 135 | + this.errorLine = errorLine; |
| 136 | + this.errorColumn = errorColumn; |
| 137 | + } |
| 138 | +} |
0 commit comments