1 | /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ |
2 | /* JavaCCOptions: */ |
3 | /* |
4 | * Copyright (C) Christian Schulte, 2005-206 |
5 | * All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
10 | * |
11 | * o Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * |
14 | * o Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in |
16 | * the documentation and/or other materials provided with the |
17 | * distribution. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
21 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * |
30 | * $JOMC: VersionParser.jj 4613 2012-09-22 10:07:08Z schulte $ |
31 | * |
32 | */ |
33 | package org.jomc.util; |
34 | |
35 | /** Token Manager Error. */ |
36 | public class TokenMgrError extends Error |
37 | { |
38 | |
39 | /** |
40 | * The version identifier for this Serializable class. |
41 | * Increment only if the <i>serialized</i> form of the |
42 | * class changes. |
43 | */ |
44 | private static final long serialVersionUID = 1L; |
45 | |
46 | /* |
47 | * Ordinals for various reasons why an Error of this type can be thrown. |
48 | */ |
49 | |
50 | /** |
51 | * Lexical error occurred. |
52 | */ |
53 | static final int LEXICAL_ERROR = 0; |
54 | |
55 | /** |
56 | * An attempt was made to create a second instance of a static token manager. |
57 | */ |
58 | static final int STATIC_LEXER_ERROR = 1; |
59 | |
60 | /** |
61 | * Tried to change to an invalid lexical state. |
62 | */ |
63 | static final int INVALID_LEXICAL_STATE = 2; |
64 | |
65 | /** |
66 | * Detected (and bailed out of) an infinite loop in the token manager. |
67 | */ |
68 | static final int LOOP_DETECTED = 3; |
69 | |
70 | /** |
71 | * Indicates the reason why the exception is thrown. It will have |
72 | * one of the above 4 values. |
73 | */ |
74 | int errorCode; |
75 | |
76 | /** |
77 | * Replaces unprintable characters by their escaped (or unicode escaped) |
78 | * equivalents in the given string |
79 | */ |
80 | protected static final String addEscapes(String str) { |
81 | StringBuffer retval = new StringBuffer(); |
82 | char ch; |
83 | for (int i = 0; i < str.length(); i++) { |
84 | switch (str.charAt(i)) |
85 | { |
86 | case 0 : |
87 | continue; |
88 | case '\b': |
89 | retval.append("\\b"); |
90 | continue; |
91 | case '\t': |
92 | retval.append("\\t"); |
93 | continue; |
94 | case '\n': |
95 | retval.append("\\n"); |
96 | continue; |
97 | case '\f': |
98 | retval.append("\\f"); |
99 | continue; |
100 | case '\r': |
101 | retval.append("\\r"); |
102 | continue; |
103 | case '\"': |
104 | retval.append("\\\""); |
105 | continue; |
106 | case '\'': |
107 | retval.append("\\\'"); |
108 | continue; |
109 | case '\\': |
110 | retval.append("\\\\"); |
111 | continue; |
112 | default: |
113 | if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
114 | String s = "0000" + Integer.toString(ch, 16); |
115 | retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
116 | } else { |
117 | retval.append(ch); |
118 | } |
119 | continue; |
120 | } |
121 | } |
122 | return retval.toString(); |
123 | } |
124 | |
125 | /** |
126 | * Returns a detailed message for the Error when it is thrown by the |
127 | * token manager to indicate a lexical error. |
128 | * Parameters : |
129 | * EOFSeen : indicates if EOF caused the lexical error |
130 | * curLexState : lexical state in which this error occurred |
131 | * errorLine : line number when the error occurred |
132 | * errorColumn : column number when the error occurred |
133 | * errorAfter : prefix that was seen before this error occurred |
134 | * curchar : the offending character |
135 | * Note: You can customize the lexical error message by modifying this method. |
136 | */ |
137 | protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { |
138 | return("Lexical error at line " + |
139 | errorLine + ", column " + |
140 | errorColumn + ". Encountered: " + |
141 | (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + |
142 | "after : \"" + addEscapes(errorAfter) + "\""); |
143 | } |
144 | |
145 | /** |
146 | * You can also modify the body of this method to customize your error messages. |
147 | * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not |
148 | * of end-users concern, so you can return something like : |
149 | * |
150 | * "Internal Error : Please file a bug report .... " |
151 | * |
152 | * from this method for such cases in the release version of your parser. |
153 | */ |
154 | public String getMessage() { |
155 | return super.getMessage(); |
156 | } |
157 | |
158 | /* |
159 | * Constructors of various flavors follow. |
160 | */ |
161 | |
162 | /** No arg constructor. */ |
163 | public TokenMgrError() { |
164 | } |
165 | |
166 | /** Constructor with message and reason. */ |
167 | public TokenMgrError(String message, int reason) { |
168 | super(message); |
169 | errorCode = reason; |
170 | } |
171 | |
172 | /** Full Constructor. */ |
173 | public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { |
174 | this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
175 | } |
176 | } |
177 | /* JavaCC - OriginalChecksum=6ad1376deb8481842d97729e265df4d1 (do not edit this line) */ |