1 2 3 6 package org.python.parser; 7 8 public class TokenMgrError extends Error 9 { 10 13 14 17 static final int LEXICAL_ERROR = 0; 18 19 22 static final int STATIC_LEXER_ERROR = 1; 23 24 27 static final int INVALID_LEXICAL_STATE = 2; 28 29 32 static final int LOOP_DETECTED = 3; 33 34 38 int errorCode; 39 40 44 protected static final String addEscapes(String str) { 45 StringBuffer retval = new StringBuffer (); 46 char ch; 47 for (int i = 0; i < str.length(); i++) { 48 switch (str.charAt(i)) 49 { 50 case 0 : 51 continue; 52 case '\b': 53 retval.append("\\b"); 54 continue; 55 case '\t': 56 retval.append("\\t"); 57 continue; 58 case '\n': 59 retval.append("\\n"); 60 continue; 61 case '\f': 62 retval.append("\\f"); 63 continue; 64 case '\r': 65 retval.append("\\r"); 66 continue; 67 case '\"': 68 retval.append("\\\""); 69 continue; 70 case '\'': 71 retval.append("\\\'"); 72 continue; 73 case '\\': 74 retval.append("\\\\"); 75 continue; 76 default: 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())); 80 } else { 81 retval.append(ch); 82 } 83 continue; 84 } 85 } 86 return retval.toString(); 87 } 88 89 101 102 public boolean EOFSeen; 104 public int errorLine, errorColumn; 105 public String curChar; 106 107 public int lexState = -1; 109 110 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 111 return("Lexical error at line " + 112 errorLine + ", column " + 113 errorColumn + ". Encountered: " + 114 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 115 "after : \"" + addEscapes(errorAfter) + "\""); 116 } 117 118 127 public String getMessage() { 128 return super.getMessage(); 129 } 130 131 134 135 public TokenMgrError() { 136 } 137 138 public TokenMgrError(String message, int reason) { 139 super(message); 140 errorCode = reason; 141 } 142 143 public TokenMgrError(String message, int errorLine, int errorColumn) { 145 this(message, LEXICAL_ERROR); 146 this.EOFSeen = false; 147 this.errorLine = errorLine; 148 this.errorColumn = errorColumn; 149 } 150 151 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 152 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, 153 errorAfter, curChar), reason); 154 this.EOFSeen = EOFSeen; 156 this.errorLine = errorLine; 157 this.errorColumn = errorColumn; 158 this.curChar = addEscapes(String.valueOf(curChar)); 159 160 this.lexState = lexState; 162 } 163 } 164 | Popular Tags |