2
* Copyright (C) 2001-2012 Michael Fuchs
4
* This file is part of herold.
6
* herold is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* herold is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with herold. If not, see <http://www.gnu.org/licenses/>.
19
package org.dbdoclet.trafo.xml.tokenizer.parser;
21
/** Token Manager Error. */
22
@SuppressWarnings("all")
23
public class TokenMgrError extends Error
27
* The version identifier for this Serializable class.
28
* Increment only if the <i>serialized</i> form of the
31
private static final long serialVersionUID = 1L;
34
* Ordinals for various reasons why an Error of this type can be thrown.
38
* Lexical error occurred.
40
static final int LEXICAL_ERROR = 0;
43
* An attempt was made to create a second instance of a static token manager.
45
static final int STATIC_LEXER_ERROR = 1;
48
* Tried to change to an invalid lexical state.
50
static final int INVALID_LEXICAL_STATE = 2;
53
* Detected (and bailed out of) an infinite loop in the token manager.
55
static final int LOOP_DETECTED = 3;
58
* Indicates the reason why the exception is thrown. It will have
59
* one of the above 4 values.
64
* Replaces unprintable characters by their escaped (or unicode escaped)
65
* equivalents in the given string
67
protected static final String addEscapes(String str) {
68
StringBuffer retval = new StringBuffer();
70
for (int i = 0; i < str.length(); i++) {
71
switch (str.charAt(i))
91
retval.append("\\\"");
94
retval.append("\\\'");
97
retval.append("\\\\");
100
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
101
String s = "0000" + Integer.toString(ch, 16);
102
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
109
return retval.toString();
113
* Returns a detailed message for the Error when it is thrown by the
114
* token manager to indicate a lexical error.
116
* EOFSeen : indicates if EOF caused the lexical error
117
* curLexState : lexical state in which this error occurred
118
* errorLine : line number when the error occurred
119
* errorColumn : column number when the error occurred
120
* errorAfter : prefix that was seen before this error occurred
121
* curchar : the offending character
122
* Note: You can customize the lexical error message by modifying this method.
124
protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
125
return("Lexical error at line " +
126
errorLine + ", column " +
127
errorColumn + ". Encountered: " +
128
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
129
"after : \"" + addEscapes(errorAfter) + "\"");
133
* You can also modify the body of this method to customize your error messages.
134
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
135
* of end-users concern, so you can return something like :
137
* "Internal Error : Please file a bug report .... "
139
* from this method for such cases in the release version of your parser.
141
public String getMessage() {
142
return super.getMessage();
146
* Constructors of various flavors follow.
149
/** No arg constructor. */
150
public TokenMgrError() {
153
/** Constructor with message and reason. */
154
public TokenMgrError(String message, int reason) {
159
/** Full Constructor. */
160
public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
161
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
164
/* JavaCC - OriginalChecksum=4018fc262b3912b4de27d74aafb44b22 (do not edit this line) */