View Javadoc

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