001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
002/* JavaCCOptions: */
003/* Parser for matrices written in matlab format.
004
005 Copyright (c) 1998-2008 The Regents of the University of California.
006 All rights reserved.
007 Permission is hereby granted, without written agreement and without
008 license or royalty fees, to use, copy, modify, and distribute this
009 software and its documentation for any purpose, provided that the above
010 copyright notice and the following two paragraphs appear in all copies
011 of this software.
012
013 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
014 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
015 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
016 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
017 SUCH DAMAGE.
018
019 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
020 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
022 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
023 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
024 ENHANCEMENTS, OR MODIFICATIONS.
025
026                                        PT_COPYRIGHT_VERSION_2
027                                        COPYRIGHTENDKEY
028 */
029package ptolemy.data.expr;
030
031/** Token Manager Error. */
032public class TokenMgrError extends Error {
033
034    /**
035     * The version identifier for this Serializable class.
036     * Increment only if the <i>serialized</i> form of the
037     * class changes.
038     */
039    private static final long serialVersionUID = 1L;
040
041    /*
042     * Ordinals for various reasons why an Error of this type can be thrown.
043     */
044
045    /**
046     * Lexical error occurred.
047     */
048    static final int LEXICAL_ERROR = 0;
049
050    /**
051     * An attempt was made to create a second instance of a static token manager.
052     */
053    static final int STATIC_LEXER_ERROR = 1;
054
055    /**
056     * Tried to change to an invalid lexical state.
057     */
058    static final int INVALID_LEXICAL_STATE = 2;
059
060    /**
061     * Detected (and bailed out of) an infinite loop in the token manager.
062     */
063    static final int LOOP_DETECTED = 3;
064
065    /**
066     * Indicates the reason why the exception is thrown. It will have
067     * one of the above 4 values.
068     */
069    int errorCode;
070
071    /**
072     * Replaces unprintable characters by their escaped (or unicode escaped)
073     * equivalents in the given string
074     */
075    protected static final String addEscapes(String str) {
076        StringBuffer retval = new StringBuffer();
077        char ch;
078        for (int i = 0; i < str.length(); i++) {
079            switch (str.charAt(i)) {
080            case 0:
081                continue;
082            case '\b':
083                retval.append("\\b");
084                continue;
085            case '\t':
086                retval.append("\\t");
087                continue;
088            case '\n':
089                retval.append("\\n");
090                continue;
091            case '\f':
092                retval.append("\\f");
093                continue;
094            case '\r':
095                retval.append("\\r");
096                continue;
097            case '\"':
098                retval.append("\\\"");
099                continue;
100            case '\'':
101                retval.append("\\\'");
102                continue;
103            case '\\':
104                retval.append("\\\\");
105                continue;
106            default:
107                if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
108                    String s = "0000" + Integer.toString(ch, 16);
109                    retval.append(
110                            "\\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 lexical error
125     *    curLexState : lexical state in which this error occurred
126     *    errorLine   : line number when the error occurred
127     *    errorColumn : column number when the error occurred
128     *    errorAfter  : prefix that was seen before this error occurred
129     *    curchar     : the offending character
130     * Note: You can customize the lexical error message by modifying this method.
131     */
132    protected static String LexicalError(boolean EOFSeen, int lexState,
133            int errorLine, int errorColumn, String errorAfter, char curChar) {
134        return ("Lexical error at line " + errorLine + ", column " + errorColumn
135                + ".  Encountered: "
136                + (EOFSeen ? "<EOF> "
137                        : ("\"" + addEscapes(String.valueOf(curChar)) + "\"")
138                                + " (" + (int) curChar + "), ")
139                + "after : \"" + addEscapes(errorAfter) + "\"");
140    }
141
142    /**
143     * You can also modify the body of this method to customize your error messages.
144     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
145     * of end-users concern, so you can return something like :
146     *
147     *     "Internal Error : Please file a bug report .... "
148     *
149     * from this method for such cases in the release version of your parser.
150     */
151    @Override
152    public String getMessage() {
153        return super.getMessage();
154    }
155
156    /*
157     * Constructors of various flavors follow.
158     */
159
160    /** No arg constructor. */
161    public TokenMgrError() {
162    }
163
164    /** Constructor with message and reason. */
165    public TokenMgrError(String message, int reason) {
166        super(message);
167        errorCode = reason;
168    }
169
170    /** Full Constructor. */
171    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine,
172            int errorColumn, String errorAfter, char curChar, int reason) {
173        this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter,
174                curChar), reason);
175    }
176}
177/* JavaCC - OriginalChecksum=2f9a34c8c3be601fce69f6a9a4253a1a (do not edit this line) */