2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
\r
9 /* JavaCCOptions:KEEP_LINE_COL=null */
\r
10 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;
\r
11 import java.util.Arrays;
\r
14 * This exception is thrown when parse errors are encountered.
\r
15 * You can explicitly create objects of this exception type by
\r
16 * calling the method generateParseException in the generated
\r
19 * You can modify this class to customize your error reporting
\r
20 * mechanisms so long as you retain the public fields.
\r
22 public class ParseException extends Exception {
\r
25 * The version identifier for this Serializable class.
\r
26 * Increment only if the <i>serialized</i> form of the
\r
29 private static final long serialVersionUID = 1L;
\r
32 * This constructor is used by the method "generateParseException"
\r
33 * in the generated parser. Calling this constructor generates
\r
34 * a new object of this type with the fields "currentToken",
\r
35 * "expectedTokenSequences", and "tokenImage" set.
\r
37 public ParseException(Token currentTokenVal,
\r
38 int[][] expectedTokenSequencesVal,
\r
39 String[] tokenImageVal
\r
43 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
\r
44 this.currentToken = currentTokenVal;
\r
45 this.tokenImage = Arrays.copyOf(tokenImageVal,tokenImageVal.length);
\r
46 this.expectedTokenSequences = Arrays.copyOf(expectedTokenSequencesVal,expectedTokenSequencesVal.length);
\r
47 // currentToken = currentTokenVal;
\r
48 // expectedTokenSequences = expectedTokenSequencesVal;
\r
49 // tokenImage = tokenImageVal;
\r
53 * The following constructors are for use by you for whatever
\r
54 * purpose you can think of. Constructing the exception in this
\r
55 * manner makes the exception behave in the normal way - i.e., as
\r
56 * documented in the class "Throwable". The fields "errorToken",
\r
57 * "expectedTokenSequences", and "tokenImage" do not contain
\r
58 * relevant information. The JavaCC generated code does not use
\r
59 * these constructors.
\r
62 public ParseException() {
\r
66 /** Constructor with message. */
\r
67 public ParseException(String message) {
\r
73 * This is the last token that has been consumed successfully. If
\r
74 * this object has been created due to a parse error, the token
\r
75 * followng this token will (therefore) be the first error token.
\r
77 public Token currentToken;
\r
80 * Each entry in this array is an array of integers. Each array
\r
81 * of integers represents a sequence of tokens (by their ordinal
\r
82 * values) that is expected at this point of the parse.
\r
84 public int[][] expectedTokenSequences;
\r
87 * This is a reference to the "tokenImage" array of the generated
\r
88 * parser within which the parse error occurred. This array is
\r
89 * defined in the generated ...Constants interface.
\r
91 public String[] tokenImage;
\r
94 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
\r
95 * error message and returns it. If this object has been created
\r
96 * due to a parse error, and you do not catch it (it gets thrown
\r
97 * from the parser) the correct error message
\r
100 private static String initialise(Token currentToken,
\r
101 int[][] expectedTokenSequences,
\r
102 String[] tokenImage) {
\r
103 String eol = System.getProperty("line.separator", "\n");
\r
104 StringBuffer expected = new StringBuffer();
\r
106 for (int i = 0; i < expectedTokenSequences.length; i++) {
\r
107 if (maxSize < expectedTokenSequences[i].length) {
\r
108 maxSize = expectedTokenSequences[i].length;
\r
110 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
\r
111 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
\r
113 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
\r
114 expected.append("...");
\r
116 expected.append(eol).append(" ");
\r
118 String retval = "Encountered \"";
\r
119 Token tok = currentToken.next;
\r
120 for (int i = 0; i < maxSize; i++) {
\r
121 if (i != 0) retval += " ";
\r
122 if (tok.kind == 0) {
\r
123 retval += tokenImage[0];
\r
126 retval += " " + tokenImage[tok.kind];
\r
128 retval += add_escapes(tok.image);
\r
132 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
\r
133 retval += "." + eol;
\r
134 if (expectedTokenSequences.length == 1) {
\r
135 retval += "Was expecting:" + eol + " ";
\r
137 retval += "Was expecting one of:" + eol + " ";
\r
139 retval += expected.toString();
\r
144 * The end of line string for this machine.
\r
146 protected String eol = System.getProperty("line.separator", "\n");
\r
149 * Used to convert raw characters to their escaped version
\r
150 * when these raw version cannot be used as part of an ASCII
\r
153 static String add_escapes(String str) {
\r
154 StringBuffer retval = new StringBuffer();
\r
156 for (int i = 0; i < str.length(); i++) {
\r
157 switch (str.charAt(i))
\r
162 retval.append("\\b");
\r
165 retval.append("\\t");
\r
168 retval.append("\\n");
\r
171 retval.append("\\f");
\r
174 retval.append("\\r");
\r
177 retval.append("\\\"");
\r
180 retval.append("\\\'");
\r
183 retval.append("\\\\");
\r
186 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
\r
187 String s = "0000" + Integer.toString(ch, 16);
\r
188 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
\r
195 return retval.toString();
\r
199 /* JavaCC - OriginalChecksum=e5e4e351aea2c3ff97c4b9bdac453a62 (do not edit this line) */
\r