001    /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
002    package org.hackystat.telemetry.analyzer.language.parser.impl;
003    
004    @SuppressWarnings("serial")
005    public class TokenMgrError extends Error
006    {
007       /*
008        * Ordinals for various reasons why an Error of this type can be thrown.
009        */
010    
011       /**
012        * Lexical error occured.
013        */
014       static final int LEXICAL_ERROR = 0;
015    
016       /**
017        * An attempt wass made to create a second instance of a static token manager.
018        */
019       static final int STATIC_LEXER_ERROR = 1;
020    
021       /**
022        * Tried to change to an invalid lexical state.
023        */
024       static final int INVALID_LEXICAL_STATE = 2;
025    
026       /**
027        * Detected (and bailed out of) an infinite loop in the token manager.
028        */
029       static final int LOOP_DETECTED = 3;
030    
031       /**
032        * Indicates the reason why the exception is thrown. It will have
033        * one of the above 4 values.
034        */
035       int errorCode;
036    
037       /**
038        * Replaces unprintable characters by their espaced (or unicode escaped)
039        * equivalents in the given string
040        */
041       protected static final String addEscapes(String str) {
042          StringBuffer retval = new StringBuffer();
043          char ch;
044          for (int i = 0; i < str.length(); i++) {
045            switch (str.charAt(i))
046            {
047               case 0 :
048                  continue;
049               case '\b':
050                  retval.append("\\b");
051                  continue;
052               case '\t':
053                  retval.append("\\t");
054                  continue;
055               case '\n':
056                  retval.append("\\n");
057                  continue;
058               case '\f':
059                  retval.append("\\f");
060                  continue;
061               case '\r':
062                  retval.append("\\r");
063                  continue;
064               case '\"':
065                  retval.append("\\\"");
066                  continue;
067               case '\'':
068                  retval.append("\\\'");
069                  continue;
070               case '\\':
071                  retval.append("\\\\");
072                  continue;
073               default:
074                  if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
075                     String s = "0000" + Integer.toString(ch, 16);
076                     retval.append("\\u" + s.substring(s.length() - 4, s.length()));
077                  } else {
078                     retval.append(ch);
079                  }
080                  continue;
081            }
082          }
083          return retval.toString();
084       }
085    
086       /**
087        * Returns a detailed message for the Error when it is thrown by the
088        * token manager to indicate a lexical error.
089        * Parameters : 
090        *    EOFSeen     : indicates if EOF caused the lexicl error
091        *    curLexState : lexical state in which this error occured
092        *    errorLine   : line number when the error occured
093        *    errorColumn : column number when the error occured
094        *    errorAfter  : prefix that was seen before this error occured
095        *    curchar     : the offending character
096        * Note: You can customize the lexical error message by modifying this method.
097        */
098       protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
099          return("Lexical error at line " +
100               errorLine + ", column " +
101               errorColumn + ".  Encountered: " +
102               (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
103               "after : \"" + addEscapes(errorAfter) + "\"");
104       }
105    
106       /**
107        * You can also modify the body of this method to customize your error messages.
108        * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
109        * of end-users concern, so you can return something like : 
110        *
111        *     "Internal Error : Please file a bug report .... "
112        *
113        * from this method for such cases in the release version of your parser.
114        */
115       @Override
116      public String getMessage() {
117          return super.getMessage();
118       }
119    
120       /*
121        * Constructors of various flavors follow.
122        */
123    
124       public TokenMgrError() {
125       }
126    
127       public TokenMgrError(String message, int reason) {
128          super(message);
129          errorCode = reason;
130       }
131    
132       public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
133          this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
134       }
135    }