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