Change the way of fetching data from datastore and write user's intents into datastor...
[nemo.git] / nemo-impl / src / main / java / org / opendaylight / nemo / user / vnspacemanager / languagestyle / NEMOParse / ParseException.java
1 /*\r
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
3  *\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
7  */\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 \r
12 /**\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
16  * parser.\r
17  *\r
18  * You can modify this class to customize your error reporting\r
19  * mechanisms so long as you retain the public fields.\r
20  */\r
21 public class ParseException extends Exception {\r
22 \r
23   /**\r
24    * The version identifier for this Serializable class.\r
25    * Increment only if the <i>serialized</i> form of the\r
26    * class changes.\r
27    */\r
28   private static final long serialVersionUID = 1L;\r
29 \r
30   /**\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
35    */\r
36   public ParseException(Token currentTokenVal,\r
37                         int[][] expectedTokenSequencesVal,\r
38                         String[] tokenImageVal\r
39                        )\r
40   {\r
41     super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));\r
42     currentToken = currentTokenVal;\r
43     expectedTokenSequences = expectedTokenSequencesVal;\r
44     tokenImage = tokenImageVal;\r
45   }\r
46 \r
47   /**\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
55    */\r
56 \r
57   public ParseException() {\r
58     super();\r
59   }\r
60 \r
61   /** Constructor with message. */\r
62   public ParseException(String message) {\r
63     super(message);\r
64   }\r
65 \r
66 \r
67   /**\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
71    */\r
72   public Token currentToken;\r
73 \r
74   /**\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
78    */\r
79   public int[][] expectedTokenSequences;\r
80 \r
81   /**\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
85    */\r
86   public String[] tokenImage;\r
87 \r
88   /**\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
93    * gets displayed.\r
94    */\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
100     int maxSize = 0;\r
101     for (int i = 0; i < expectedTokenSequences.length; i++) {\r
102       if (maxSize < expectedTokenSequences[i].length) {\r
103         maxSize = expectedTokenSequences[i].length;\r
104       }\r
105       for (int j = 0; j < expectedTokenSequences[i].length; j++) {\r
106         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');\r
107       }\r
108       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {\r
109         expected.append("...");\r
110       }\r
111       expected.append(eol).append("    ");\r
112     }\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
119         break;\r
120       }\r
121       retval += " " + tokenImage[tok.kind];\r
122       retval += " \"";\r
123       retval += add_escapes(tok.image);\r
124       retval += " \"";\r
125       tok = tok.next;\r
126     }\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
131     } else {\r
132       retval += "Was expecting one of:" + eol + "    ";\r
133     }\r
134     retval += expected.toString();\r
135     return retval;\r
136   }\r
137 \r
138   /**\r
139    * The end of line string for this machine.\r
140    */\r
141   protected String eol = System.getProperty("line.separator", "\n");\r
142 \r
143   /**\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
146    * string literal.\r
147    */\r
148   static String add_escapes(String str) {\r
149       StringBuffer retval = new StringBuffer();\r
150       char ch;\r
151       for (int i = 0; i < str.length(); i++) {\r
152         switch (str.charAt(i))\r
153         {\r
154            case 0 :\r
155               continue;\r
156            case '\b':\r
157               retval.append("\\b");\r
158               continue;\r
159            case '\t':\r
160               retval.append("\\t");\r
161               continue;\r
162            case '\n':\r
163               retval.append("\\n");\r
164               continue;\r
165            case '\f':\r
166               retval.append("\\f");\r
167               continue;\r
168            case '\r':\r
169               retval.append("\\r");\r
170               continue;\r
171            case '\"':\r
172               retval.append("\\\"");\r
173               continue;\r
174            case '\'':\r
175               retval.append("\\\'");\r
176               continue;\r
177            case '\\':\r
178               retval.append("\\\\");\r
179               continue;\r
180            default:\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
184               } else {\r
185                  retval.append(ch);\r
186               }\r
187               continue;\r
188         }\r
189       }\r
190       return retval.toString();\r
191    }\r
192 \r
193 }\r
194 /* JavaCC - OriginalChecksum=e5e4e351aea2c3ff97c4b9bdac453a62 (do not edit this line) */\r