KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

30
31    /**
32     * Lexical error occured.
33     */

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

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

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

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

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

61    protected static final String JavaDoc addEscapes(String JavaDoc str) {
62       StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
63       char ch;
64       for (int i = 0; i < str.length(); i++) {
65         switch (str.charAt(i))
66         {
67            case 0 :
68               continue;
69            case '\b':
70               retval.append("\\b");
71               continue;
72            case '\t':
73               retval.append("\\t");
74               continue;
75            case '\n':
76               retval.append("\\n");
77               continue;
78            case '\f':
79               retval.append("\\f");
80               continue;
81            case '\r':
82               retval.append("\\r");
83               continue;
84            case '\"':
85               retval.append("\\\"");
86               continue;
87            case '\'':
88               retval.append("\\\'");
89               continue;
90            case '\\':
91               retval.append("\\\\");
92               continue;
93            default:
94               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
95                  String JavaDoc s = "0000" + Integer.toString(ch, 16);
96                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
97               } else {
98                  retval.append(ch);
99               }
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 JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc 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 JavaDoc 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 JavaDoc message, int reason) {
147       super(message);
148       errorCode = reason;
149    }
150
151    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
152       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
153    }
154 }
155
Popular Tags