1 2 6 7 package com.hp.hpl.jena.rdql.parser; 8 9 public class TokenMgrError extends Error 10 { 11 14 15 18 static final int LEXICAL_ERROR = 0; 19 20 23 static final int STATIC_LEXER_ERROR = 1; 24 25 28 static final int INVALID_LEXICAL_STATE = 2; 29 30 33 static final int LOOP_DETECTED = 3; 34 35 39 int errorCode; 40 41 45 protected static final String addEscapes(String str) { 46 StringBuffer retval = new StringBuffer (); 47 char ch; 48 for (int i = 0; i < str.length(); i++) { 49 switch (str.charAt(i)) 50 { 51 case 0 : 52 continue; 53 case '\b': 54 retval.append("\\b"); 55 continue; 56 case '\t': 57 retval.append("\\t"); 58 continue; 59 case '\n': 60 retval.append("\\n"); 61 continue; 62 case '\f': 63 retval.append("\\f"); 64 continue; 65 case '\r': 66 retval.append("\\r"); 67 continue; 68 case '\"': 69 retval.append("\\\""); 70 continue; 71 case '\'': 72 retval.append("\\\'"); 73 continue; 74 case '\\': 75 retval.append("\\\\"); 76 continue; 77 default: 78 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 79 String s = "0000" + Integer.toString(ch, 16); 80 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 81 } else { 82 retval.append(ch); 83 } 84 continue; 85 } 86 } 87 return retval.toString(); 88 } 89 90 102 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 103 return("Lexical error at line " + 104 errorLine + ", column " + 105 errorColumn + ". Encountered: " + 106 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 107 "after : \"" + addEscapes(errorAfter) + "\""); 108 } 109 110 119 public String getMessage() { 120 return super.getMessage(); 121 } 122 123 126 127 public TokenMgrError() { 128 } 129 130 public TokenMgrError(String message, int reason) { 131 super(message); 132 errorCode = reason; 133 } 134 135 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 136 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 137 } 138 } 139 | Popular Tags |