1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */
3 package org.apache.lucene.queryParser.standard.parser;
5 /** Token Manager Error. */
6 @SuppressWarnings("serial")
7 public class TokenMgrError extends Error
11 * Ordinals for various reasons why an Error of this type can be thrown.
15 * Lexical error occurred.
17 static final int LEXICAL_ERROR = 0;
20 * An attempt was made to create a second instance of a static token manager.
22 static final int STATIC_LEXER_ERROR = 1;
25 * Tried to change to an invalid lexical state.
27 static final int INVALID_LEXICAL_STATE = 2;
30 * Detected (and bailed out of) an infinite loop in the token manager.
32 static final int LOOP_DETECTED = 3;
35 * Indicates the reason why the exception is thrown. It will have
36 * one of the above 4 values.
41 * Replaces unprintable characters by their escaped (or unicode escaped)
42 * equivalents in the given string
44 protected static final String addEscapes(String str) {
45 StringBuffer retval = new StringBuffer();
47 for (int i = 0; i < str.length(); i++) {
48 switch (str.charAt(i))
68 retval.append("\\\"");
71 retval.append("\\\'");
74 retval.append("\\\\");
77 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
78 String s = "0000" + Integer.toString(ch, 16);
79 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
86 return retval.toString();
90 * Returns a detailed message for the Error when it is thrown by the
91 * token manager to indicate a lexical error.
93 * EOFSeen : indicates if EOF caused the lexical error
94 * curLexState : lexical state in which this error occurred
95 * errorLine : line number when the error occurred
96 * errorColumn : column number when the error occurred
97 * errorAfter : prefix that was seen before this error occurred
98 * curchar : the offending character
99 * Note: You can customize the lexical error message by modifying this method.
101 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
102 return("Lexical error at line " +
103 errorLine + ", column " +
104 errorColumn + ". Encountered: " +
105 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
106 "after : \"" + addEscapes(errorAfter) + "\"");
110 * You can also modify the body of this method to customize your error messages.
111 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
112 * of end-users concern, so you can return something like :
114 * "Internal Error : Please file a bug report .... "
116 * from this method for such cases in the release version of your parser.
118 public String getMessage() {
119 return super.getMessage();
123 * Constructors of various flavors follow.
126 /** No arg constructor. */
127 public TokenMgrError() {
130 /** Constructor with message and reason. */
131 public TokenMgrError(String message, int reason) {
136 /** Full Constructor. */
137 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
138 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
141 /* JavaCC - OriginalChecksum=a75b5b61664a73631a032a6e44f4b38a (do not edit this line) */