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