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