KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > micronova > util > cc > html > TokenMgrError


1 /*
2
3 Copyright 2003-2007 MicroNova (R)
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or
7 without modification, are permitted provided that the following
8 conditions are met:
9
10     * Redistributions of source code must retain the above copyright
11     notice, this list of conditions and the following disclaimer.
12
13     * Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17     * Neither the name of MicroNova nor the names of its contributors
18     may be used to endorse or promote products derived from this
19     software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32
33 */

34
35
36 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
37 package com.micronova.util.cc.html;
38
39 public class TokenMgrError extends Error JavaDoc
40 {
41    /*
42     * Ordinals for various reasons why an Error of this type can be thrown.
43     */

44
45    /**
46     * Lexical error occured.
47     */

48    static final int LEXICAL_ERROR = 0;
49
50    /**
51     * An attempt wass made to create a second instance of a static token manager.
52     */

53    static final int STATIC_LEXER_ERROR = 1;
54
55    /**
56     * Tried to change to an invalid lexical state.
57     */

58    static final int INVALID_LEXICAL_STATE = 2;
59
60    /**
61     * Detected (and bailed out of) an infinite loop in the token manager.
62     */

63    static final int LOOP_DETECTED = 3;
64
65    /**
66     * Indicates the reason why the exception is thrown. It will have
67     * one of the above 4 values.
68     */

69    int errorCode;
70
71    /**
72     * Replaces unprintable characters by their espaced (or unicode escaped)
73     * equivalents in the given string
74     */

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

132    protected static String JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar) {
133       return("Lexical error at line " +
134            errorLine + ", column " +
135            errorColumn + ". Encountered: " +
136            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
137            "after : \"" + addEscapes(errorAfter) + "\"");
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(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
166       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
167    }
168 }
169
Popular Tags