e2e9f63a26624b207669d92e6fc436183f069532
[nemo.git] / nemo-impl / src / main / java / org / opendaylight / nemo / user / vnspacemanager / languagestyle / NEMOParse / TokenMgrError.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. TokenMgrError.java Version 5.0 */\r
9 /* JavaCCOptions: */\r
10 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;\r
11 \r
12 /** Token Manager Error. */\r
13 public class TokenMgrError extends Error\r
14 {\r
15 \r
16   /**\r
17    * The version identifier for this Serializable class.\r
18    * Increment only if the <i>serialized</i> form of the\r
19    * class changes.\r
20    */\r
21   private static final long serialVersionUID = 1L;\r
22 \r
23   /*\r
24    * Ordinals for various reasons why an Error of this type can be thrown.\r
25    */\r
26 \r
27   /**\r
28    * Lexical error occurred.\r
29    */\r
30   static final int LEXICAL_ERROR = 0;\r
31 \r
32   /**\r
33    * An attempt was made to create a second instance of a static token manager.\r
34    */\r
35   static final int STATIC_LEXER_ERROR = 1;\r
36 \r
37   /**\r
38    * Tried to change to an invalid lexical state.\r
39    */\r
40   static final int INVALID_LEXICAL_STATE = 2;\r
41 \r
42   /**\r
43    * Detected (and bailed out of) an infinite loop in the token manager.\r
44    */\r
45   static final int LOOP_DETECTED = 3;\r
46 \r
47   /**\r
48    * Indicates the reason why the exception is thrown. It will have\r
49    * one of the above 4 values.\r
50    */\r
51   int errorCode;\r
52 \r
53   /**\r
54    * Replaces unprintable characters by their escaped (or unicode escaped)\r
55    * equivalents in the given string\r
56    */\r
57   protected static final String addEscapes(String str) {\r
58     StringBuffer retval = new StringBuffer();\r
59     char ch;\r
60     for (int i = 0; i < str.length(); i++) {\r
61       switch (str.charAt(i))\r
62       {\r
63         case 0 :\r
64           continue;\r
65         case '\b':\r
66           retval.append("\\b");\r
67           continue;\r
68         case '\t':\r
69           retval.append("\\t");\r
70           continue;\r
71         case '\n':\r
72           retval.append("\\n");\r
73           continue;\r
74         case '\f':\r
75           retval.append("\\f");\r
76           continue;\r
77         case '\r':\r
78           retval.append("\\r");\r
79           continue;\r
80         case '\"':\r
81           retval.append("\\\"");\r
82           continue;\r
83         case '\'':\r
84           retval.append("\\\'");\r
85           continue;\r
86         case '\\':\r
87           retval.append("\\\\");\r
88           continue;\r
89         default:\r
90           if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {\r
91             String s = "0000" + Integer.toString(ch, 16);\r
92             retval.append("\\u" + s.substring(s.length() - 4, s.length()));\r
93           } else {\r
94             retval.append(ch);\r
95           }\r
96           continue;\r
97       }\r
98     }\r
99     return retval.toString();\r
100   }\r
101 \r
102   /**\r
103    * Returns a detailed message for the Error when it is thrown by the\r
104    * token manager to indicate a lexical error.\r
105    * Parameters :\r
106    *    EOFSeen     : indicates if EOF caused the lexical error\r
107    *    curLexState : lexical state in which this error occurred\r
108    *    errorLine   : line number when the error occurred\r
109    *    errorColumn : column number when the error occurred\r
110    *    errorAfter  : prefix that was seen before this error occurred\r
111    *    curchar     : the offending character\r
112    * Note: You can customize the lexical error message by modifying this method.\r
113    */\r
114   protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {\r
115     return("Lexical error at line " +\r
116           errorLine + ", column " +\r
117           errorColumn + ".  Encountered: " +\r
118           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +\r
119           "after : \"" + addEscapes(errorAfter) + "\"");\r
120   }\r
121 \r
122   /**\r
123    * You can also modify the body of this method to customize your error messages.\r
124    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not\r
125    * of end-users concern, so you can return something like :\r
126    *\r
127    *     "Internal Error : Please file a bug report .... "\r
128    *\r
129    * from this method for such cases in the release version of your parser.\r
130    */\r
131   public String getMessage() {\r
132     return super.getMessage();\r
133   }\r
134 \r
135   /*\r
136    * Constructors of various flavors follow.\r
137    */\r
138 \r
139   /** No arg constructor. */\r
140   public TokenMgrError() {\r
141   }\r
142 \r
143   /** Constructor with message and reason. */\r
144   public TokenMgrError(String message, int reason) {\r
145     super(message);\r
146     errorCode = reason;\r
147   }\r
148 \r
149   /** Full Constructor. */\r
150   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {\r
151     this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);\r
152   }\r
153 }\r
154 /* JavaCC - OriginalChecksum=91ec89f496ecd57e6511b78a642440de (do not edit this line) */\r