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/] [ParseException.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. ParseException.java Version 5.0 */
2
/* JavaCCOptions:KEEP_LINE_COL=null */
3
/*
4
@LICENSE@
5
*/
6
package edu.byu.cc.plieber.fpgaenet.debug.llparse;
7
 
8
/**
9
 * This exception is thrown when parse errors are encountered.
10
 * You can explicitly create objects of this exception type by
11
 * calling the method generateParseException in the generated
12
 * parser.
13
 *
14
 * You can modify this class to customize your error reporting
15
 * mechanisms so long as you retain the public fields.
16
 */
17
public class ParseException extends Exception {
18
 
19
  /**
20
   * The version identifier for this Serializable class.
21
   * Increment only if the <i>serialized</i> form of the
22
   * class changes.
23
   */
24
  private static final long serialVersionUID = 1L;
25
 
26
  /**
27
   * This constructor is used by the method "generateParseException"
28
   * in the generated parser.  Calling this constructor generates
29
   * a new object of this type with the fields "currentToken",
30
   * "expectedTokenSequences", and "tokenImage" set.
31
   */
32
  public ParseException(Token currentTokenVal,
33
                        int[][] expectedTokenSequencesVal,
34
                        String[] tokenImageVal
35
                       )
36
  {
37
    super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
38
    currentToken = currentTokenVal;
39
    expectedTokenSequences = expectedTokenSequencesVal;
40
    tokenImage = tokenImageVal;
41
  }
42
 
43
  /**
44
   * The following constructors are for use by you for whatever
45
   * purpose you can think of.  Constructing the exception in this
46
   * manner makes the exception behave in the normal way - i.e., as
47
   * documented in the class "Throwable".  The fields "errorToken",
48
   * "expectedTokenSequences", and "tokenImage" do not contain
49
   * relevant information.  The JavaCC generated code does not use
50
   * these constructors.
51
   */
52
 
53
  public ParseException() {
54
    super();
55
  }
56
 
57
  /** Constructor with message. */
58
  public ParseException(String message) {
59
    super(message);
60
  }
61
 
62
 
63
  /**
64
   * This is the last token that has been consumed successfully.  If
65
   * this object has been created due to a parse error, the token
66
   * followng this token will (therefore) be the first error token.
67
   */
68
  public Token currentToken;
69
 
70
  /**
71
   * Each entry in this array is an array of integers.  Each array
72
   * of integers represents a sequence of tokens (by their ordinal
73
   * values) that is expected at this point of the parse.
74
   */
75
  public int[][] expectedTokenSequences;
76
 
77
  /**
78
   * This is a reference to the "tokenImage" array of the generated
79
   * parser within which the parse error occurred.  This array is
80
   * defined in the generated ...Constants interface.
81
   */
82
  public String[] tokenImage;
83
 
84
  /**
85
   * It uses "currentToken" and "expectedTokenSequences" to generate a parse
86
   * error message and returns it.  If this object has been created
87
   * due to a parse error, and you do not catch it (it gets thrown
88
   * from the parser) the correct error message
89
   * gets displayed.
90
   */
91
  private static String initialise(Token currentToken,
92
                           int[][] expectedTokenSequences,
93
                           String[] tokenImage) {
94
    String eol = System.getProperty("line.separator", "\n");
95
    StringBuffer expected = new StringBuffer();
96
    int maxSize = 0;
97
    for (int i = 0; i < expectedTokenSequences.length; i++) {
98
      if (maxSize < expectedTokenSequences[i].length) {
99
        maxSize = expectedTokenSequences[i].length;
100
      }
101
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
102
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
103
      }
104
      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
105
        expected.append("...");
106
      }
107
      expected.append(eol).append("    ");
108
    }
109
    String retval = "Encountered \"";
110
    Token tok = currentToken.next;
111
    for (int i = 0; i < maxSize; i++) {
112
      if (i != 0) retval += " ";
113
      if (tok.kind == 0) {
114
        retval += tokenImage[0];
115
        break;
116
      }
117
      retval += " " + tokenImage[tok.kind];
118
      retval += " \"";
119
      retval += add_escapes(tok.image);
120
      retval += " \"";
121
      tok = tok.next;
122
    }
123
    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
124
    retval += "." + eol;
125
    if (expectedTokenSequences.length == 1) {
126
      retval += "Was expecting:" + eol + "    ";
127
    } else {
128
      retval += "Was expecting one of:" + eol + "    ";
129
    }
130
    retval += expected.toString();
131
    return retval;
132
  }
133
 
134
  /**
135
   * The end of line string for this machine.
136
   */
137
  protected String eol = System.getProperty("line.separator", "\n");
138
 
139
  /**
140
   * Used to convert raw characters to their escaped version
141
   * when these raw version cannot be used as part of an ASCII
142
   * string literal.
143
   */
144
  static String add_escapes(String str) {
145
      StringBuffer retval = new StringBuffer();
146
      char ch;
147
      for (int i = 0; i < str.length(); i++) {
148
        switch (str.charAt(i))
149
        {
150
           case 0 :
151
              continue;
152
           case '\b':
153
              retval.append("\\b");
154
              continue;
155
           case '\t':
156
              retval.append("\\t");
157
              continue;
158
           case '\n':
159
              retval.append("\\n");
160
              continue;
161
           case '\f':
162
              retval.append("\\f");
163
              continue;
164
           case '\r':
165
              retval.append("\\r");
166
              continue;
167
           case '\"':
168
              retval.append("\\\"");
169
              continue;
170
           case '\'':
171
              retval.append("\\\'");
172
              continue;
173
           case '\\':
174
              retval.append("\\\\");
175
              continue;
176
           default:
177
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
178
                 String s = "0000" + Integer.toString(ch, 16);
179
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
180
              } else {
181
                 retval.append(ch);
182
              }
183
              continue;
184
        }
185
      }
186
      return retval.toString();
187
   }
188
 
189
}
190
/* JavaCC - OriginalChecksum=f9ad4f1b9326cd17d0da7a5456484dd5 (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.