OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [debug/] [llparse/] [TokenMgrError.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
2
/* JavaCCOptions: */
3
/*
4
@LICENSE@
5
*/
6
package edu.byu.cc.plieber.fpgaenet.debug.llparse;
7
 
8
/** Token Manager Error. */
9
public class TokenMgrError extends Error
10
{
11
 
12
  /**
13
   * The version identifier for this Serializable class.
14
   * Increment only if the <i>serialized</i> form of the
15
   * class changes.
16
   */
17
  private static final long serialVersionUID = 1L;
18
 
19
  /*
20
   * Ordinals for various reasons why an Error of this type can be thrown.
21
   */
22
 
23
  /**
24
   * Lexical error occurred.
25
   */
26
  static final int LEXICAL_ERROR = 0;
27
 
28
  /**
29
   * An attempt was made to create a second instance of a static token manager.
30
   */
31
  static final int STATIC_LEXER_ERROR = 1;
32
 
33
  /**
34
   * Tried to change to an invalid lexical state.
35
   */
36
  static final int INVALID_LEXICAL_STATE = 2;
37
 
38
  /**
39
   * Detected (and bailed out of) an infinite loop in the token manager.
40
   */
41
  static final int LOOP_DETECTED = 3;
42
 
43
  /**
44
   * Indicates the reason why the exception is thrown. It will have
45
   * one of the above 4 values.
46
   */
47
  int errorCode;
48
 
49
  /**
50
   * Replaces unprintable characters by their escaped (or unicode escaped)
51
   * equivalents in the given string
52
   */
53
  protected static final String addEscapes(String str) {
54
    StringBuffer retval = new StringBuffer();
55
    char ch;
56
    for (int i = 0; i < str.length(); i++) {
57
      switch (str.charAt(i))
58
      {
59
        case 0 :
60
          continue;
61
        case '\b':
62
          retval.append("\\b");
63
          continue;
64
        case '\t':
65
          retval.append("\\t");
66
          continue;
67
        case '\n':
68
          retval.append("\\n");
69
          continue;
70
        case '\f':
71
          retval.append("\\f");
72
          continue;
73
        case '\r':
74
          retval.append("\\r");
75
          continue;
76
        case '\"':
77
          retval.append("\\\"");
78
          continue;
79
        case '\'':
80
          retval.append("\\\'");
81
          continue;
82
        case '\\':
83
          retval.append("\\\\");
84
          continue;
85
        default:
86
          if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
87
            String s = "0000" + Integer.toString(ch, 16);
88
            retval.append("\\u" + s.substring(s.length() - 4, s.length()));
89
          } else {
90
            retval.append(ch);
91
          }
92
          continue;
93
      }
94
    }
95
    return retval.toString();
96
  }
97
 
98
  /**
99
   * Returns a detailed message for the Error when it is thrown by the
100
   * token manager to indicate a lexical error.
101
   * Parameters :
102
   *    EOFSeen     : indicates if EOF caused the lexical error
103
   *    curLexState : lexical state in which this error occurred
104
   *    errorLine   : line number when the error occurred
105
   *    errorColumn : column number when the error occurred
106
   *    errorAfter  : prefix that was seen before this error occurred
107
   *    curchar     : the offending character
108
   * Note: You can customize the lexical error message by modifying this method.
109
   */
110
  protected static 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
  /**
119
   * You can also modify the body of this method to customize your error messages.
120
   * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
121
   * of end-users concern, so you can return something like :
122
   *
123
   *     "Internal Error : Please file a bug report .... "
124
   *
125
   * from this method for such cases in the release version of your parser.
126
   */
127
  public String getMessage() {
128
    return super.getMessage();
129
  }
130
 
131
  /*
132
   * Constructors of various flavors follow.
133
   */
134
 
135
  /** No arg constructor. */
136
  public TokenMgrError() {
137
  }
138
 
139
  /** Constructor with message and reason. */
140
  public TokenMgrError(String message, int reason) {
141
    super(message);
142
    errorCode = reason;
143
  }
144
 
145
  /** Full Constructor. */
146
  public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
147
    this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
148
  }
149
}
150
/* JavaCC - OriginalChecksum=f5500fb6f1bc8a5280fe3ae76a821bcc (do not edit this line) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.