001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
002/* JavaCCOptions: */
003/*
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_3
027                                        COPYRIGHTENDKEY
028 */
029
030package ptolemy.moml.unit;
031
032/** Token Manager Error. */
033public class TokenMgrError extends Error {
034
035    /**
036     * The version identifier for this Serializable class.
037     * Increment only if the <i>serialized</i> form of the
038     * class changes.
039     */
040    private static final long serialVersionUID = 1L;
041
042    /*
043     * Ordinals for various reasons why an Error of this type can be thrown.
044     */
045
046    /**
047     * Lexical error occurred.
048     */
049    static final int LEXICAL_ERROR = 0;
050
051    /**
052     * An attempt was made to create a second instance of a static token manager.
053     */
054    static final int STATIC_LEXER_ERROR = 1;
055
056    /**
057     * Tried to change to an invalid lexical state.
058     */
059    static final int INVALID_LEXICAL_STATE = 2;
060
061    /**
062     * Detected (and bailed out of) an infinite loop in the token manager.
063     */
064    static final int LOOP_DETECTED = 3;
065
066    /**
067     * Indicates the reason why the exception is thrown. It will have
068     * one of the above 4 values.
069     */
070    int errorCode;
071
072    /**
073     * Replaces unprintable characters by their escaped (or unicode escaped)
074     * equivalents in the given string
075     */
076    protected static final String addEscapes(String str) {
077        StringBuffer retval = new StringBuffer();
078        char ch;
079        for (int i = 0; i < str.length(); i++) {
080            switch (str.charAt(i)) {
081            case 0:
082                continue;
083            case '\b':
084                retval.append("\\b");
085                continue;
086            case '\t':
087                retval.append("\\t");
088                continue;
089            case '\n':
090                retval.append("\\n");
091                continue;
092            case '\f':
093                retval.append("\\f");
094                continue;
095            case '\r':
096                retval.append("\\r");
097                continue;
098            case '\"':
099                retval.append("\\\"");
100                continue;
101            case '\'':
102                retval.append("\\\'");
103                continue;
104            case '\\':
105                retval.append("\\\\");
106                continue;
107            default:
108                if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
109                    String s = "0000" + Integer.toString(ch, 16);
110                    retval.append(
111                            "\\u" + s.substring(s.length() - 4, s.length()));
112                } else {
113                    retval.append(ch);
114                }
115                continue;
116            }
117        }
118        return retval.toString();
119    }
120
121    /**
122     * Returns a detailed message for the Error when it is thrown by the
123     * token manager to indicate a lexical error.
124     * Parameters :
125     *    EOFSeen     : indicates if EOF caused the lexical error
126     *    curLexState : lexical state in which this error occurred
127     *    errorLine   : line number when the error occurred
128     *    errorColumn : column number when the error occurred
129     *    errorAfter  : prefix that was seen before this error occurred
130     *    curchar     : the offending character
131     * Note: You can customize the lexical error message by modifying this method.
132     */
133    protected static String LexicalError(boolean EOFSeen, int lexState,
134            int errorLine, int errorColumn, String errorAfter, char curChar) {
135        return "Lexical error at line " + errorLine + ", column " + errorColumn
136                + ".  Encountered: "
137                + (EOFSeen ? "<EOF> "
138                        : "\"" + addEscapes(String.valueOf(curChar)) + "\""
139                                + " (" + (int) curChar + "), ")
140                + "after : \"" + addEscapes(errorAfter) + "\"";
141    }
142
143    /**
144     * You can also modify the body of this method to customize your error messages.
145     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
146     * of end-users concern, so you can return something like :
147     *
148     *     "Internal Error : Please file a bug report .... "
149     *
150     * from this method for such cases in the release version of your parser.
151     */
152    @Override
153    public String getMessage() {
154        return super.getMessage();
155    }
156
157    /*
158     * Constructors of various flavors follow.
159     */
160
161    /** No arg constructor. */
162    public TokenMgrError() {
163    }
164
165    /** Constructor with message and reason. */
166    public TokenMgrError(String message, int reason) {
167        super(message);
168        errorCode = reason;
169    }
170
171    /** Full Constructor. */
172    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine,
173            int errorColumn, String errorAfter, char curChar, int reason) {
174        this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter,
175                curChar), reason);
176    }
177}
178/* JavaCC - OriginalChecksum=c2b8ceabb4bc42ab01c911dcbb9e153b (do not edit this line) */