1/* 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ 27/* JavaCCOptions: */ 28package com.sun.tools.example.debug.expr; 29 30/** Token Manager Error. */ 31public class TokenMgrError extends Error 32{ 33 34 /** 35 * The version identifier for this Serializable class. 36 * Increment only if the <i>serialized</i> form of the 37 * class changes. 38 */ 39 private static final long serialVersionUID = 1L; 40 41 /* 42 * Ordinals for various reasons why an Error of this type can be thrown. 43 */ 44 45 /** 46 * Lexical error occurred. 47 */ 48 static final int LEXICAL_ERROR = 0; 49 50 /** 51 * An attempt was made to create a second instance of a static token manager. 52 */ 53 static final int STATIC_LEXER_ERROR = 1; 54 55 /** 56 * Tried to change to an invalid lexical state. 57 */ 58 static final int INVALID_LEXICAL_STATE = 2; 59 60 /** 61 * Detected (and bailed out of) an infinite loop in the token manager. 62 */ 63 static final int LOOP_DETECTED = 3; 64 65 /** 66 * Indicates the reason why the exception is thrown. It will have 67 * one of the above 4 values. 68 */ 69 int errorCode; 70 71 /** 72 * Replaces unprintable characters by their escaped (or unicode escaped) 73 * equivalents in the given string 74 */ 75 protected static final String addEscapes(String str) { 76 StringBuilder retval = new StringBuilder(); 77 char ch; 78 for (int i = 0; i < str.length(); i++) { 79 switch (str.charAt(i)) 80 { 81 case 0 : 82 continue; 83 case '\b': 84 retval.append("\\b"); 85 continue; 86 case '\t': 87 retval.append("\\t"); 88 continue; 89 case '\n': 90 retval.append("\\n"); 91 continue; 92 case '\f': 93 retval.append("\\f"); 94 continue; 95 case '\r': 96 retval.append("\\r"); 97 continue; 98 case '\"': 99 retval.append("\\\""); 100 continue; 101 case '\'': 102 retval.append("\\\'"); 103 continue; 104 case '\\': 105 retval.append("\\\\"); 106 continue; 107 default: 108 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 109 String s = "0000" + Integer.toString(ch, 16); 110 retval.append("\\u").append(s.substring(s.length() - 4, s.length())); 111 } else { 112 retval.append(ch); 113 } 114 continue; 115 } 116 } 117 return retval.toString(); 118 } 119 120 /** 121 * Returns a detailed message for the Error when it is thrown by the 122 * token manager to indicate a lexical error. 123 * Parameters : 124 * EOFSeen : indicates if EOF caused the lexical error 125 * curLexState : lexical state in which this error occurred 126 * errorLine : line number when the error occurred 127 * errorColumn : column number when the error occurred 128 * errorAfter : prefix that was seen before this error occurred 129 * curchar : the offending character 130 * Note: You can customize the lexical error message by modifying this method. 131 */ 132 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 133 return("Lexical error at line " + 134 errorLine + ", column " + 135 errorColumn + ". Encountered: " + 136 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 137 "after : \"" + addEscapes(errorAfter) + "\""); 138 } 139 140 /** 141 * You can also modify the body of this method to customize your error messages. 142 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 143 * of end-users concern, so you can return something like : 144 * 145 * "Internal Error : Please file a bug report .... " 146 * 147 * from this method for such cases in the release version of your parser. 148 */ 149 public String getMessage() { 150 return super.getMessage(); 151 } 152 153 /* 154 * Constructors of various flavors follow. 155 */ 156 157 /** No arg constructor. */ 158 public TokenMgrError() { 159 } 160 161 /** Constructor with message and reason. */ 162 public TokenMgrError(String message, int reason) { 163 super(message); 164 errorCode = reason; 165 } 166 167 /** Full Constructor. */ 168 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 169 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 170 } 171} 172/* JavaCC - OriginalChecksum=9b5d040f247411cad7f77688386c48e7 (do not edit this line) */ 173