~ubuntu-branches/ubuntu/vivid/herold/vivid

« back to all changes in this revision

Viewing changes to java/org/dbdoclet/trafo/xml/tokenizer/parser/TokenMgrError.java

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2012-09-20 10:00:14 UTC
  • Revision ID: package-import@ubuntu.com-20120920100014-5pcwbw2err6on8yg
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

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