KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2 /*****************************************************************
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  ****************************************************************/

20
21
22 package org.apache.cayenne.exp.parser;
23
24 class TokenMgrError extends Error JavaDoc {
25     /*
26      * Ordinals for various reasons why an Error of this type can be thrown.
27      */

28
29     /**
30      * Lexical error occured.
31      */

32     static final int LEXICAL_ERROR = 0;
33
34     /**
35      * An attempt wass made to create a second instance of a static token manager.
36      */

37     static final int STATIC_LEXER_ERROR = 1;
38
39     /**
40      * Tried to change to an invalid lexical state.
41      */

42     static final int INVALID_LEXICAL_STATE = 2;
43
44     /**
45      * Detected (and bailed out of) an infinite loop in the token manager.
46      */

47     static final int LOOP_DETECTED = 3;
48
49     /**
50      * Indicates the reason why the exception is thrown. It will have
51      * one of the above 4 values.
52      */

53     int errorCode;
54
55     /**
56      * Replaces unprintable characters by their espaced (or unicode escaped)
57      * equivalents in the given string
58      */

59     protected static final String JavaDoc addEscapes(String JavaDoc str) {
60         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
61         char ch;
62         for (int i = 0; i < str.length(); i++) {
63             switch (str.charAt(i)) {
64                 case 0 :
65                     continue;
66                 case '\b' :
67                     retval.append("\\b");
68                     continue;
69                 case '\t' :
70                     retval.append("\\t");
71                     continue;
72                 case '\n' :
73                     retval.append("\\n");
74                     continue;
75                 case '\f' :
76                     retval.append("\\f");
77                     continue;
78                 case '\r' :
79                     retval.append("\\r");
80                     continue;
81                 case '\"' :
82                     retval.append("\\\"");
83                     continue;
84                 case '\'' :
85                     retval.append("\\\'");
86                     continue;
87                 case '\\' :
88                     retval.append("\\\\");
89                     continue;
90                 default :
91                     if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
92                         String JavaDoc s = "0000" + Integer.toString(ch, 16);
93                         retval.append("\\u" + s.substring(s.length() - 4, s.length()));
94                     }
95                     else {
96                         retval.append(ch);
97                     }
98                     continue;
99             }
100         }
101         return retval.toString();
102     }
103
104     /**
105      * Returns a detailed message for the Error when it is thrown by the
106      * token manager to indicate a lexical error.
107      * Parameters :
108      * EOFSeen : indicates if EOF caused the lexicl error
109      * curLexState : lexical state in which this error occured
110      * errorLine : line number when the error occured
111      * errorColumn : column number when the error occured
112      * errorAfter : prefix that was seen before this error occured
113      * curchar : the offending character
114      * Note: You can customize the lexical error message by modifying this method.
115      */

116     protected static String JavaDoc LexicalError(
117         boolean EOFSeen,
118         int lexState,
119         int errorLine,
120         int errorColumn,
121         String JavaDoc errorAfter,
122         char curChar) {
123         return (
124             "Lexical error at line "
125                 + errorLine
126                 + ", column "
127                 + errorColumn
128                 + ". Encountered: "
129                 + (EOFSeen
130                     ? "<EOF> "
131                     : ("\"" + addEscapes(String.valueOf(curChar)) + "\"")
132                         + " ("
133                         + (int) curChar
134                         + "), ")
135                 + "after : \""
136                 + addEscapes(errorAfter)
137                 + "\"");
138     }
139
140     /**
141      * You can also modify the body of this method to customize your error messages.
142      * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
143      * of end-users concern, so you can return something like :
144      *
145      * "Internal Error : Please file a bug report .... "
146      *
147      * from this method for such cases in the release version of your parser.
148      */

149     public String JavaDoc getMessage() {
150         return super.getMessage();
151     }
152
153     /*
154      * Constructors of various flavors follow.
155      */

156
157     public TokenMgrError() {
158     }
159
160     public TokenMgrError(String JavaDoc message, int reason) {
161         super(message);
162         errorCode = reason;
163     }
164
165     public TokenMgrError(
166         boolean EOFSeen,
167         int lexState,
168         int errorLine,
169         int errorColumn,
170         String JavaDoc errorAfter,
171         char curChar,
172         int reason) {
173         this(
174             LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar),
175             reason);
176     }
177 }
178
Popular Tags