KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
2 /*
3  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
4  * All rights reserved.
5  */

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

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

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

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

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

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

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

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

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

119    public String JavaDoc getMessage() {
120       return super.getMessage();
121    }
122
123    /*
124     * Constructors of various flavors follow.
125     */

126
127    public TokenMgrError() {
128    }
129
130    public TokenMgrError(String JavaDoc message, int reason) {
131       super(message);
132       errorCode = reason;
133    }
134
135    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
136       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
137    }
138 }
139
Popular Tags