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