| 1 | /* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 1.1 */ |
|---|---|
| 2 | /* ParserGeneratorCCOptions: */ |
| 3 | /* |
| 4 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
| 5 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
| 6 | * |
| 7 | * This file is part of JavaParser. |
| 8 | * |
| 9 | * JavaParser can be used either under the terms of |
| 10 | * a) the GNU Lesser General Public License as published by |
| 11 | * the Free Software Foundation, either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * b) the terms of the Apache License |
| 14 | * |
| 15 | * You should have received a copy of both licenses in LICENCE.LGPL and |
| 16 | * LICENCE.APACHE. Please refer to those files for details. |
| 17 | * |
| 18 | * JavaParser is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU Lesser General Public License for more details. |
| 22 | */ |
| 23 | package com.github.javaparser; |
| 24 | |
| 25 | /** Token Manager Error. */ |
| 26 | public class TokenMgrException extends RuntimeException |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * The version identifier for this Serializable class. |
| 31 | * Increment only if the <i>serialized</i> form of the |
| 32 | * class changes. |
| 33 | */ |
| 34 | private static final long serialVersionUID = 1L; |
| 35 | |
| 36 | /* |
| 37 | * Ordinals for various reasons why an Error of this type can be thrown. |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | * Lexical error occurred. |
| 42 | */ |
| 43 | public static final int LEXICAL_ERROR = 0; |
| 44 | |
| 45 | /** |
| 46 | * An attempt was made to create a second instance of a static token manager. |
| 47 | */ |
| 48 | public static final int STATIC_LEXER_ERROR = 1; |
| 49 | |
| 50 | /** |
| 51 | * Tried to change to an invalid lexical state. |
| 52 | */ |
| 53 | public static final int INVALID_LEXICAL_STATE = 2; |
| 54 | |
| 55 | /** |
| 56 | * Detected (and bailed out of) an infinite loop in the token manager. |
| 57 | */ |
| 58 | public static final int LOOP_DETECTED = 3; |
| 59 | |
| 60 | /** |
| 61 | * Indicates the reason why the exception is thrown. It will have |
| 62 | * one of the above 4 values. |
| 63 | */ |
| 64 | int errorCode; |
| 65 | |
| 66 | /** |
| 67 | * Replaces unprintable characters by their escaped (or unicode escaped) |
| 68 | * equivalents in the given string |
| 69 | */ |
| 70 | protected static final String addEscapes(String str) { |
| 71 | StringBuilder retval = new StringBuilder(); |
| 72 | for (int i = 0; i < str.length(); i++) { |
| 73 | final char ch = str.charAt(i); |
| 74 | switch (ch) |
| 75 | { |
| 76 | case '\b': |
| 77 | retval.append("\\b"); |
| 78 | continue; |
| 79 | case '\t': |
| 80 | retval.append("\\t"); |
| 81 | continue; |
| 82 | case '\n': |
| 83 | retval.append("\\n"); |
| 84 | continue; |
| 85 | case '\f': |
| 86 | retval.append("\\f"); |
| 87 | continue; |
| 88 | case '\r': |
| 89 | retval.append("\\r"); |
| 90 | continue; |
| 91 | case '\"': |
| 92 | retval.append("\\\""); |
| 93 | continue; |
| 94 | case '\'': |
| 95 | retval.append("\\\'"); |
| 96 | continue; |
| 97 | case '\\': |
| 98 | retval.append("\\\\"); |
| 99 | continue; |
| 100 | default: |
| 101 | if (ch < 0x20 || ch > 0x7e) { |
| 102 | String s = "0000" + Integer.toString(ch, 16); |
| 103 | retval.append("\\u").append (s.substring(s.length() - 4, s.length())); |
| 104 | } else { |
| 105 | retval.append(ch); |
| 106 | } |
| 107 | continue; |
| 108 | } |
| 109 | } |
| 110 | return retval.toString(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns a detailed message for the Error when it is thrown by the |
| 115 | * token manager to indicate a lexical error. |
| 116 | * Parameters : |
| 117 | * EOFSeen : indicates if EOF caused the lexical error |
| 118 | * curLexState : lexical state in which this error occurred |
| 119 | * errorLine : line number when the error occurred |
| 120 | * errorColumn : column number when the error occurred |
| 121 | * errorAfter : prefix that was seen before this error occurred |
| 122 | * curchar : the offending character |
| 123 | * Note: You can customize the lexical error message by modifying this method. |
| 124 | */ |
| 125 | protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { |
| 126 | char curChar1 = (char)curChar; |
| 127 | return("Lexical error at line " + |
| 128 | errorLine + ", column " + |
| 129 | errorColumn + ". Encountered: " + |
| 130 | (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + |
| 131 | "after : \"" + addEscapes(errorAfter) + "\""); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * You can also modify the body of this method to customize your error messages. |
| 136 | * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not |
| 137 | * of end-users concern, so you can return something like : |
| 138 | * |
| 139 | * "Internal Error : Please file a bug report .... " |
| 140 | * |
| 141 | * from this method for such cases in the release version of your parser. |
| 142 | */ |
| 143 | @Override |
| 144 | public String getMessage() { |
| 145 | return super.getMessage(); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Constructors of various flavors follow. |
| 150 | */ |
| 151 | /** No arg constructor. */ |
| 152 | public TokenMgrException() { |
| 153 | } |
| 154 | |
| 155 | /** Constructor with message and reason. */ |
| 156 | public TokenMgrException(String message, int reason) { |
| 157 | super(message); |
| 158 | errorCode = reason; |
| 159 | } |
| 160 | |
| 161 | /** Full Constructor. */ |
| 162 | public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { |
| 163 | this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
| 164 | } |
| 165 | } |
| 166 | /* ParserGeneratorCC - OriginalChecksum=a5b40635733540f78f08e08a19200223 (do not edit this line) */ |
| 167 |
Members