KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > exp > parser > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2 /* ====================================================================
3  *
4  * The ObjectStyle Group Software License, version 1.1
5  * ObjectStyle Group - http://objectstyle.org/
6  *
7  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
8  * of the software. All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  *
22  * 3. The end-user documentation included with the redistribution, if any,
23  * must include the following acknowlegement:
24  * "This product includes software developed by independent contributors
25  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
26  * Alternately, this acknowlegement may appear in the software itself,
27  * if and wherever such third-party acknowlegements normally appear.
28  *
29  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
30  * or promote products derived from this software without prior written
31  * permission. For written permission, email
32  * "andrus at objectstyle dot org".
33  *
34  * 5. Products derived from this software may not be called "ObjectStyle"
35  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
36  * names without prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals and hosted on ObjectStyle Group web site. For more
54  * information on the ObjectStyle Group, please see
55  * <http://objectstyle.org/>.
56  */

57
58 package org.objectstyle.cayenne.exp.parser;
59
60 class TokenMgrError extends Error JavaDoc {
61     /*
62      * Ordinals for various reasons why an Error of this type can be thrown.
63      */

64
65     /**
66      * Lexical error occured.
67      */

68     static final int LEXICAL_ERROR = 0;
69
70     /**
71      * An attempt wass made to create a second instance of a static token manager.
72      */

73     static final int STATIC_LEXER_ERROR = 1;
74
75     /**
76      * Tried to change to an invalid lexical state.
77      */

78     static final int INVALID_LEXICAL_STATE = 2;
79
80     /**
81      * Detected (and bailed out of) an infinite loop in the token manager.
82      */

83     static final int LOOP_DETECTED = 3;
84
85     /**
86      * Indicates the reason why the exception is thrown. It will have
87      * one of the above 4 values.
88      */

89     int errorCode;
90
91     /**
92      * Replaces unprintable characters by their espaced (or unicode escaped)
93      * equivalents in the given string
94      */

95     protected static final String JavaDoc addEscapes(String JavaDoc str) {
96         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
97         char ch;
98         for (int i = 0; i < str.length(); i++) {
99             switch (str.charAt(i)) {
100                 case 0 :
101                     continue;
102                 case '\b' :
103                     retval.append("\\b");
104                     continue;
105                 case '\t' :
106                     retval.append("\\t");
107                     continue;
108                 case '\n' :
109                     retval.append("\\n");
110                     continue;
111                 case '\f' :
112                     retval.append("\\f");
113                     continue;
114                 case '\r' :
115                     retval.append("\\r");
116                     continue;
117                 case '\"' :
118                     retval.append("\\\"");
119                     continue;
120                 case '\'' :
121                     retval.append("\\\'");
122                     continue;
123                 case '\\' :
124                     retval.append("\\\\");
125                     continue;
126                 default :
127                     if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
128                         String JavaDoc s = "0000" + Integer.toString(ch, 16);
129                         retval.append("\\u" + s.substring(s.length() - 4, s.length()));
130                     }
131                     else {
132                         retval.append(ch);
133                     }
134                     continue;
135             }
136         }
137         return retval.toString();
138     }
139
140     /**
141      * Returns a detailed message for the Error when it is thrown by the
142      * token manager to indicate a lexical error.
143      * Parameters :
144      * EOFSeen : indicates if EOF caused the lexicl error
145      * curLexState : lexical state in which this error occured
146      * errorLine : line number when the error occured
147      * errorColumn : column number when the error occured
148      * errorAfter : prefix that was seen before this error occured
149      * curchar : the offending character
150      * Note: You can customize the lexical error message by modifying this method.
151      */

152     protected static String JavaDoc LexicalError(
153         boolean EOFSeen,
154         int lexState,
155         int errorLine,
156         int errorColumn,
157         String JavaDoc errorAfter,
158         char curChar) {
159         return (
160             "Lexical error at line "
161                 + errorLine
162                 + ", column "
163                 + errorColumn
164                 + ". Encountered: "
165                 + (EOFSeen
166                     ? "<EOF> "
167                     : ("\"" + addEscapes(String.valueOf(curChar)) + "\"")
168                         + " ("
169                         + (int) curChar
170                         + "), ")
171                 + "after : \""
172                 + addEscapes(errorAfter)
173                 + "\"");
174     }
175
176     /**
177      * You can also modify the body of this method to customize your error messages.
178      * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
179      * of end-users concern, so you can return something like :
180      *
181      * "Internal Error : Please file a bug report .... "
182      *
183      * from this method for such cases in the release version of your parser.
184      */

185     public String JavaDoc getMessage() {
186         return super.getMessage();
187     }
188
189     /*
190      * Constructors of various flavors follow.
191      */

192
193     public TokenMgrError() {
194     }
195
196     public TokenMgrError(String JavaDoc message, int reason) {
197         super(message);
198         errorCode = reason;
199     }
200
201     public TokenMgrError(
202         boolean EOFSeen,
203         int lexState,
204         int errorLine,
205         int errorColumn,
206         String JavaDoc errorAfter,
207         char curChar,
208         int reason) {
209         this(
210             LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar),
211             reason);
212     }
213 }
214
Popular Tags