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
13 * This exception is thrown when parse errors are encountered.
\r
14 * You can explicitly create objects of this exception type by
\r
15 * calling the method generateParseException in the generated
\r
18 * You can modify this class to customize your error reporting
\r
19 * mechanisms so long as you retain the public fields.
\r
21 public class ParseException extends Exception {
\r
24 * The version identifier for this Serializable class.
\r
25 * Increment only if the <i>serialized</i> form of the
\r
28 private static final long serialVersionUID = 1L;
\r
31 * This constructor is used by the method "generateParseException"
\r
32 * in the generated parser. Calling this constructor generates
\r
33 * a new object of this type with the fields "currentToken",
\r
34 * "expectedTokenSequences", and "tokenImage" set.
\r
36 public ParseException(Token currentTokenVal,
\r
37 int[][] expectedTokenSequencesVal,
\r
38 String[] tokenImageVal
\r
41 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
\r
42 currentToken = currentTokenVal;
\r
43 expectedTokenSequences = expectedTokenSequencesVal;
\r
44 tokenImage = tokenImageVal;
\r
48 * The following constructors are for use by you for whatever
\r
49 * purpose you can think of. Constructing the exception in this
\r
50 * manner makes the exception behave in the normal way - i.e., as
\r
51 * documented in the class "Throwable". The fields "errorToken",
\r
52 * "expectedTokenSequences", and "tokenImage" do not contain
\r
53 * relevant information. The JavaCC generated code does not use
\r
54 * these constructors.
\r
57 public ParseException() {
\r
61 /** Constructor with message. */
\r
62 public ParseException(String message) {
\r
68 * This is the last token that has been consumed successfully. If
\r
69 * this object has been created due to a parse error, the token
\r
70 * followng this token will (therefore) be the first error token.
\r
72 public Token currentToken;
\r
75 * Each entry in this array is an array of integers. Each array
\r
76 * of integers represents a sequence of tokens (by their ordinal
\r
77 * values) that is expected at this point of the parse.
\r
79 public int[][] expectedTokenSequences;
\r
82 * This is a reference to the "tokenImage" array of the generated
\r
83 * parser within which the parse error occurred. This array is
\r
84 * defined in the generated ...Constants interface.
\r
86 public String[] tokenImage;
\r
89 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
\r
90 * error message and returns it. If this object has been created
\r
91 * due to a parse error, and you do not catch it (it gets thrown
\r
92 * from the parser) the correct error message
\r
95 private static String initialise(Token currentToken,
\r
96 int[][] expectedTokenSequences,
\r
97 String[] tokenImage) {
\r
98 String eol = System.getProperty("line.separator", "\n");
\r
99 StringBuffer expected = new StringBuffer();
\r
101 for (int i = 0; i < expectedTokenSequences.length; i++) {
\r
102 if (maxSize < expectedTokenSequences[i].length) {
\r
103 maxSize = expectedTokenSequences[i].length;
\r
105 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
\r
106 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
\r
108 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
\r
109 expected.append("...");
\r
111 expected.append(eol).append(" ");
\r
113 String retval = "Encountered \"";
\r
114 Token tok = currentToken.next;
\r
115 for (int i = 0; i < maxSize; i++) {
\r
116 if (i != 0) retval += " ";
\r
117 if (tok.kind == 0) {
\r
118 retval += tokenImage[0];
\r
121 retval += " " + tokenImage[tok.kind];
\r
123 retval += add_escapes(tok.image);
\r
127 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
\r
128 retval += "." + eol;
\r
129 if (expectedTokenSequences.length == 1) {
\r
130 retval += "Was expecting:" + eol + " ";
\r
132 retval += "Was expecting one of:" + eol + " ";
\r
134 retval += expected.toString();
\r
139 * The end of line string for this machine.
\r
141 protected String eol = System.getProperty("line.separator", "\n");
\r
144 * Used to convert raw characters to their escaped version
\r
145 * when these raw version cannot be used as part of an ASCII
\r
148 static String add_escapes(String str) {
\r
149 StringBuffer retval = new StringBuffer();
\r
151 for (int i = 0; i < str.length(); i++) {
\r
152 switch (str.charAt(i))
\r
157 retval.append("\\b");
\r
160 retval.append("\\t");
\r
163 retval.append("\\n");
\r
166 retval.append("\\f");
\r
169 retval.append("\\r");
\r
172 retval.append("\\\"");
\r
175 retval.append("\\\'");
\r
178 retval.append("\\\\");
\r
181 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
\r
182 String s = "0000" + Integer.toString(ch, 16);
\r
183 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
\r
190 return retval.toString();
\r
194 /* JavaCC - OriginalChecksum=e5e4e351aea2c3ff97c4b9bdac453a62 (do not edit this line) */
\r