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