View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
17  package org.seasar.tuigwaa.cms.core.wiki.engine;
18  
19  public class TokenMgrError extends Error
20  {
21     /*
22      * Ordinals for various reasons why an Error of this type can be thrown.
23      */
24  
25     /***
26  	 * 
27  	 */
28  	private static final long serialVersionUID = -6372620625095654048L;
29  
30  /***
31      * Lexical error occured.
32      */
33     static final int LEXICAL_ERROR = 0;
34  
35     /***
36      * An attempt wass made to create a second instance of a static token manager.
37      */
38     static final int STATIC_LEXER_ERROR = 1;
39  
40     /***
41      * Tried to change to an invalid lexical state.
42      */
43     static final int INVALID_LEXICAL_STATE = 2;
44  
45     /***
46      * Detected (and bailed out of) an infinite loop in the token manager.
47      */
48     static final int LOOP_DETECTED = 3;
49  
50     /***
51      * Indicates the reason why the exception is thrown. It will have
52      * one of the above 4 values.
53      */
54     int errorCode;
55  
56     /***
57      * Replaces unprintable characters by their espaced (or unicode escaped)
58      * equivalents in the given string
59      */
60     protected static final String addEscapes(String str) {
61        StringBuffer retval = new StringBuffer();
62        char ch;
63        for (int i = 0; i < str.length(); i++) {
64          switch (str.charAt(i))
65          {
66             case 0 :
67                continue;
68             case '\b':
69                retval.append("//b");
70                continue;
71             case '\t':
72                retval.append("//t");
73                continue;
74             case '\n':
75                retval.append("//n");
76                continue;
77             case '\f':
78                retval.append("//f");
79                continue;
80             case '\r':
81                retval.append("//r");
82                continue;
83             case '\"':
84                retval.append("//\"");
85                continue;
86             case '\'':
87                retval.append("//\'");
88                continue;
89             case '//':
90                retval.append("////");
91                continue;
92             default:
93                if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
94                   String s = "0000" + Integer.toString(ch, 16);
95                   retval.append("//u" + s.substring(s.length() - 4, s.length()));
96                } else {
97                   retval.append(ch);
98                }
99                continue;
100         }
101       }
102       return retval.toString();
103    }
104 
105    /***
106     * Returns a detailed message for the Error when it is thrown by the
107     * token manager to indicate a lexical error.
108     * Parameters : 
109     *    EOFSeen     : indicates if EOF caused the lexicl error
110     *    curLexState : lexical state in which this error occured
111     *    errorLine   : line number when the error occured
112     *    errorColumn : column number when the error occured
113     *    errorAfter  : prefix that was seen before this error occured
114     *    curchar     : the offending character
115     * Note: You can customize the lexical error message by modifying this method.
116     */
117    protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
118       return("Lexical error at line " +
119            errorLine + ", column " +
120            errorColumn + ".  Encountered: " +
121            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
122            "after : \"" + addEscapes(errorAfter) + "\"");
123    }
124 
125    /***
126     * You can also modify the body of this method to customize your error messages.
127     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
128     * of end-users concern, so you can return something like : 
129     *
130     *     "Internal Error : Please file a bug report .... "
131     *
132     * from this method for such cases in the release version of your parser.
133     */
134    public String getMessage() {
135       return super.getMessage();
136    }
137 
138    /*
139     * Constructors of various flavors follow.
140     */
141 
142    public TokenMgrError() {
143    }
144 
145    public TokenMgrError(String message, int reason) {
146       super(message);
147       errorCode = reason;
148    }
149 
150    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
151       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
152    }
153 }