KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > parser > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
2
3 // Hacked by baw 12-Mar-1999 because JavaCC does not seem to be generating
4
// the same class structure as it was before :-(
5

6 package org.python.parser;
7
8 public class TokenMgrError extends Error JavaDoc
9 {
10    /*
11     * Ordinals for various reasons why an Error of this type can be thrown.
12     */

13
14    /**
15     * Lexical error occured.
16     */

17    static final int LEXICAL_ERROR = 0;
18
19    /**
20     * An attempt wass made to create a second instance of a static token manager.
21     */

22    static final int STATIC_LEXER_ERROR = 1;
23
24    /**
25     * Tried to change to an invalid lexical state.
26     */

27    static final int INVALID_LEXICAL_STATE = 2;
28
29    /**
30     * Detected (and bailed out of) an infinite loop in the token manager.
31     */

32    static final int LOOP_DETECTED = 3;
33
34    /**
35     * Indicates the reason why the exception is thrown. It will have
36     * one of the above 4 values.
37     */

38    int errorCode;
39
40    /**
41     * Replaces unprintable characters by their espaced (or unicode escaped)
42     * equivalents in the given string
43     */

44    protected static final String JavaDoc addEscapes(String JavaDoc str) {
45       StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
46       char ch;
47       for (int i = 0; i < str.length(); i++) {
48         switch (str.charAt(i))
49         {
50            case 0 :
51               continue;
52            case '\b':
53               retval.append("\\b");
54               continue;
55            case '\t':
56               retval.append("\\t");
57               continue;
58            case '\n':
59               retval.append("\\n");
60               continue;
61            case '\f':
62               retval.append("\\f");
63               continue;
64            case '\r':
65               retval.append("\\r");
66               continue;
67            case '\"':
68               retval.append("\\\"");
69               continue;
70            case '\'':
71               retval.append("\\\'");
72               continue;
73            case '\\':
74               retval.append("\\\\");
75               continue;
76            default:
77               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
78                  String JavaDoc s = "0000" + Integer.toString(ch, 16);
79                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
80               } else {
81                  retval.append(ch);
82               }
83               continue;
84         }
85       }
86       return retval.toString();
87    }
88
89    /**
90     * Returns a detailed message for the Error when it is thrown by the
91     * token manager to indicate a lexical error.
92     * Parameters :
93     * EOFSeen : indicates if EOF caused the lexicl error
94     * curLexState : lexical state in which this error occured
95     * errorLine : line number when the error occured
96     * errorColumn : column number when the error occured
97     * errorAfter : prefix that was seen before this error occured
98     * curchar : the offending character
99     * Note: You can customize the lexical error message by modifying this method.
100     */

101
102    // added: 12-Mar-1999 (baw)
103
public boolean EOFSeen;
104    public int errorLine, errorColumn;
105    public String JavaDoc curChar;
106     
107    // 8-May-2003 (pedronis)
108
public int lexState = -1;
109
110    private static final String JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar) {
111       return("Lexical error at line " +
112            errorLine + ", column " +
113            errorColumn + ". Encountered: " +
114            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
115            "after : \"" + addEscapes(errorAfter) + "\"");
116    }
117
118    /**
119     * You can also modify the body of this method to customize your error messages.
120     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
121     * of end-users concern, so you can return something like :
122     *
123     * "Internal Error : Please file a bug report .... "
124     *
125     * from this method for such cases in the release version of your parser.
126     */

127    public String JavaDoc getMessage() {
128       return super.getMessage();
129    }
130
131    /*
132     * Constructors of various flavors follow.
133     */

134
135    public TokenMgrError() {
136    }
137
138    public TokenMgrError(String JavaDoc message, int reason) {
139       super(message);
140       errorCode = reason;
141    }
142
143     // added: 12-Mar-1999 baw
144
public TokenMgrError(String JavaDoc message, int errorLine, int errorColumn) {
145       this(message, LEXICAL_ERROR);
146            this.EOFSeen = false;
147            this.errorLine = errorLine;
148            this.errorColumn = errorColumn;
149    }
150
151    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
152       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn,
153                         errorAfter, curChar), reason);
154       // modified: 12-Mar-1999 baw
155
this.EOFSeen = EOFSeen;
156       this.errorLine = errorLine;
157       this.errorColumn = errorColumn;
158       this.curChar = addEscapes(String.valueOf(curChar));
159       
160       // 8-May-2003 (pedronis)
161
this.lexState = lexState;
162    }
163 }
164
Popular Tags