001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
002:/***********************************************************************************************************************
003: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- * The software in this package is
005: * published under the terms of the LGPL license * a copy of which has been included with this distribution in the
006: * license.txt file. *
007: **********************************************************************************************************************/package org.codehaus.aspectwerkz.expression.ast;
008:
009:public class TokenMgrError extends Error {
010: /*
011: * Ordinals for various reasons why an Error of this type can be thrown.
012: */
013:
014: /**
015: * Lexical error occured.
016: */
017: static final int LEXICAL_ERROR = 0;
018:
019: /**
020: * An attempt wass made to create a second instance of a static token manager.
021: */
022: static final int STATIC_LEXER_ERROR = 1;
023:
024: /**
025: * Tried to change to an invalid lexical state.
026: */
027: static final int INVALID_LEXICAL_STATE = 2;
028:
029: /**
030: * Detected (and bailed out of) an infinite loop in the token manager.
031: */
032: static final int LOOP_DETECTED = 3;
033:
034: /**
035: * Indicates the reason why the exception is thrown. It will have one of the above 4 values.
036: */
037: int errorCode;
038:
039: /**
040: * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
041: */
042: protected static final String addEscapes(String str) {
043: StringBuffer retval = new StringBuffer();
044: char ch;
045: for (int i = 0; i < str.length(); i++) {
046: switch (str.charAt(i)) {
047: case 0:
048: continue;
049: case '\b':
050: retval.append("\\b");
051: continue;
052: case '\t':
053: retval.append("\\t");
054: continue;
055: case '\n':
056: retval.append("\\n");
057: continue;
058: case '\f':
059: retval.append("\\f");
060: continue;
061: case '\r':
062: retval.append("\\r");
063: continue;
064: case '\"':
065: retval.append("\\\"");
066: continue;
067: case '\'':
068: retval.append("\\\'");
069: continue;
070: case '\\':
071: retval.append("\\\\");
072: continue;
073: default:
074: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
075: String s = "0000" + Integer.toString(ch, 16);
076: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
077: } else {
078: retval.append(ch);
079: }
080: continue;
081: }
082: }
083: return retval.toString();
084: }
085:
086: /**
087: * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
088: * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
089: * occured errorLine : line number when the error occured errorColumn : column number when the error occured
090: * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can
091: * customize the lexical error message by modifying this method.
092: */
093: protected static String LexicalError(boolean EOFSeen,
094: int lexState,
095: int errorLine,
096: int errorColumn,
097: String errorAfter,
098: char curChar) {
099: return ("Lexical error at line "
100: + errorLine
101: + ", column "
102: + errorColumn
103: + ". Encountered: "
104: +
105: (EOFSeen ?
106: "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ")
107: + "after : \""
108: + addEscapes(errorAfter) + "\"");
109: }
110:
111: /**
112: * You can also modify the body of this method to customize your error messages. For example, cases like
113: * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
114: * "Internal Error : Please file a bug report .... " from this method for such cases in the release version of your
115: * parser.
116: */
117: public String getMessage() {
118: return super .getMessage();
119: }
120:
121: /*
122: * Constructors of various flavors follow.
123: */
124:
125: public TokenMgrError() {
126: }
127:
128: public TokenMgrError(String message, int reason) {
129: super (message);
130: errorCode = reason;
131: }
132:
133: public TokenMgrError(boolean EOFSeen,
134: int lexState,
135: int errorLine,
136: int errorColumn,
137: String errorAfter,
138: char curChar,
139: int reason) {
140: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
141: }
142:}
|