source: proiecte/HadoopJUnit/hadoop-0.20.1/src/core/org/apache/hadoop/record/compiler/generated/TokenMgrError.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.7 KB
Line 
1/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2/**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.apache.hadoop.record.compiler.generated;
21
22public class TokenMgrError extends Error
23{
24  /*
25   * Ordinals for various reasons why an Error of this type can be thrown.
26   */
27
28  /**
29   * Lexical error occured.
30   */
31  static final int LEXICAL_ERROR = 0;
32
33  /**
34   * An attempt wass made to create a second instance of a static token manager.
35   */
36  static final int STATIC_LEXER_ERROR = 1;
37
38  /**
39   * Tried to change to an invalid lexical state.
40   */
41  static final int INVALID_LEXICAL_STATE = 2;
42
43  /**
44   * Detected (and bailed out of) an infinite loop in the token manager.
45   */
46  static final int LOOP_DETECTED = 3;
47
48  /**
49   * Indicates the reason why the exception is thrown. It will have
50   * one of the above 4 values.
51   */
52  int errorCode;
53
54  /**
55   * Replaces unprintable characters by their espaced (or unicode escaped)
56   * equivalents in the given string
57   */
58  protected static final String addEscapes(String str) {
59    StringBuffer retval = new StringBuffer();
60    char ch;
61    for (int i = 0; i < str.length(); i++) {
62      switch (str.charAt(i))
63        {
64        case 0 :
65          continue;
66        case '\b':
67          retval.append("\\b");
68          continue;
69        case '\t':
70          retval.append("\\t");
71          continue;
72        case '\n':
73          retval.append("\\n");
74          continue;
75        case '\f':
76          retval.append("\\f");
77          continue;
78        case '\r':
79          retval.append("\\r");
80          continue;
81        case '\"':
82          retval.append("\\\"");
83          continue;
84        case '\'':
85          retval.append("\\\'");
86          continue;
87        case '\\':
88          retval.append("\\\\");
89          continue;
90        default:
91          if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
92            String s = "0000" + Integer.toString(ch, 16);
93            retval.append("\\u" + s.substring(s.length() - 4, s.length()));
94          } else {
95            retval.append(ch);
96          }
97          continue;
98        }
99    }
100    return retval.toString();
101  }
102
103  /**
104   * Returns a detailed message for the Error when it is thrown by the
105   * token manager to indicate a lexical error.
106   * Parameters :
107   *    EOFSeen     : indicates if EOF caused the lexicl error
108   *    curLexState : lexical state in which this error occured
109   *    errorLine   : line number when the error occured
110   *    errorColumn : column number when the error occured
111   *    errorAfter  : prefix that was seen before this error occured
112   *    curchar     : the offending character
113   * Note: You can customize the lexical error message by modifying this method.
114   */
115  protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
116    return("Lexical error at line " +
117           errorLine + ", column " +
118           errorColumn + ".  Encountered: " +
119           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
120           "after : \"" + addEscapes(errorAfter) + "\"");
121  }
122
123  /**
124   * You can also modify the body of this method to customize your error messages.
125   * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
126   * of end-users concern, so you can return something like :
127   *
128   *     "Internal Error : Please file a bug report .... "
129   *
130   * from this method for such cases in the release version of your parser.
131   */
132  public String getMessage() {
133    return super.getMessage();
134  }
135
136  /*
137   * Constructors of various flavors follow.
138   */
139
140  public TokenMgrError() {
141  }
142
143  public TokenMgrError(String message, int reason) {
144    super(message);
145    errorCode = reason;
146  }
147
148  public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
149    this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
150  }
151}
Note: See TracBrowser for help on using the repository browser.