Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/tripi/asp/parse/TokenMgrError.java


1   /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
2   package com.tripi.asp.parse;
3   
4   public class TokenMgrError extends Error
5   {
6      /*
7       * Ordinals for various reasons why an Error of this type can be thrown.
8       */
9   
10     /**
11      * Lexical error occured.
12      */
13     static final int LEXICAL_ERROR = 0;
14  
15     /**
16      * An attempt wass made to create a second instance of a static token manager.
17      */
18     static final int STATIC_LEXER_ERROR = 1;
19  
20     /**
21      * Tried to change to an invalid lexical state.
22      */
23     static final int INVALID_LEXICAL_STATE = 2;
24  
25     /**
26      * Detected (and bailed out of) an infinite loop in the token manager.
27      */
28     static final int LOOP_DETECTED = 3;
29  
30     /**
31      * Indicates the reason why the exception is thrown. It will have
32      * one of the above 4 values.
33      */
34     int errorCode;
35  
36     /**
37      * The file where the error occured.
38      */
39     String filename = null;
40  
41     /**
42      * The line number where the error occured.
43      */
44     int lineno = 0;
45  
46     /**
47      * Obtain the filename where the problem occured.
48      */
49     public String getFilename()
50     {
51        return filename;
52     }
53  
54     /**
55      * Set the filename where the problem occured.
56      */
57     public void setFilename(String filename)
58     {
59        this.filename = filename;
60     }
61  
62     /**
63      * Obtain the line number where the problem occured.
64      */
65     public int getLineNo()
66     {
67        return lineno;
68     }
69  
70     /**
71      * Replaces unprintable characters by their espaced (or unicode escaped)
72      * equivalents in the given string
73      */
74     protected static final String addEscapes(String str) {
75        StringBuffer retval = new StringBuffer();
76        char ch;
77        for (int i = 0; i < str.length(); i++) {
78          switch (str.charAt(i))
79          {
80             case 0 :
81                continue;
82             case '\b':
83                retval.append("\\b");
84                continue;
85             case '\t':
86                retval.append("\\t");
87                continue;
88             case '\n':
89                retval.append("\\n");
90                continue;
91             case '\f':
92                retval.append("\\f");
93                continue;
94             case '\r':
95                retval.append("\\r");
96                continue;
97             case '\"':
98                retval.append("\\\"");
99                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("\\u" + s.substring(s.length() - 4, s.length()));
110               } else {
111                  retval.append(ch);
112               }
113               continue;
114         }
115       }
116       return retval.toString();
117    }
118 
119    /**
120     * Returns a detailed message for the Error when it is thrown by the
121     * token manager to indicate a lexical error.
122     * Parameters : 
123     *    EOFSeen     : indicates if EOF caused the lexicl error
124     *    curLexState : lexical state in which this error occured
125     *    errorLine   : line number when the error occured
126     *    errorColumn : column number when the error occured
127     *    errorAfter  : prefix that was seen before this error occured
128     *    curchar     : the offending character
129     * Note: You can customize the lexical error message by modifying this method.
130     */
131    private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
132       return("Lexical error at line " +
133            errorLine + ", column " +
134            errorColumn + ".  Encountered: " +
135            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
136            "after : \"" + addEscapes(errorAfter) + "\"");
137    }
138 
139    /**
140     * You can also modify the body of this method to customize your error messages.
141     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
142     * of end-users concern, so you can return something like : 
143     *
144     *     "Internal Error : Please file a bug report .... "
145     *
146     * from this method for such cases in the release version of your parser.
147     */
148    public String getMessage() {
149       return super.getMessage();
150    }
151 
152    /*
153     * Constructors of various flavors follow.
154     */
155 
156    public TokenMgrError() {
157    }
158 
159    public TokenMgrError(String message, int reason) {
160       super(message);
161       errorCode = reason;
162    }
163 
164    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
165       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
166       this.lineno = errorLine;
167    }
168 }