]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/parser/ParseException.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / internal / parser / ParseException.java
1 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */\r
2 /* JavaCCOptions:KEEP_LINE_COL=null */\r
3 package org.simantics.graphviz.internal.parser;\r
4 \r
5 /**\r
6  * This exception is thrown when parse errors are encountered.\r
7  * You can explicitly create objects of this exception type by\r
8  * calling the method generateParseException in the generated\r
9  * parser.\r
10  *\r
11  * You can modify this class to customize your error reporting\r
12  * mechanisms so long as you retain the public fields.\r
13  */\r
14 public class ParseException extends Exception {\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    * This constructor is used by the method "generateParseException"\r
25    * in the generated parser.  Calling this constructor generates\r
26    * a new object of this type with the fields "currentToken",\r
27    * "expectedTokenSequences", and "tokenImage" set.\r
28    */\r
29   public ParseException(Token currentTokenVal,\r
30                         int[][] expectedTokenSequencesVal,\r
31                         String[] tokenImageVal\r
32                        )\r
33   {\r
34     super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));\r
35     currentToken = currentTokenVal;\r
36     expectedTokenSequences = expectedTokenSequencesVal;\r
37     tokenImage = tokenImageVal;\r
38   }\r
39 \r
40   /**\r
41    * The following constructors are for use by you for whatever\r
42    * purpose you can think of.  Constructing the exception in this\r
43    * manner makes the exception behave in the normal way - i.e., as\r
44    * documented in the class "Throwable".  The fields "errorToken",\r
45    * "expectedTokenSequences", and "tokenImage" do not contain\r
46    * relevant information.  The JavaCC generated code does not use\r
47    * these constructors.\r
48    */\r
49 \r
50   public ParseException() {\r
51     super();\r
52   }\r
53 \r
54   /** Constructor with message. */\r
55   public ParseException(String message) {\r
56     super(message);\r
57   }\r
58 \r
59 \r
60   /**\r
61    * This is the last token that has been consumed successfully.  If\r
62    * this object has been created due to a parse error, the token\r
63    * followng this token will (therefore) be the first error token.\r
64    */\r
65   public Token currentToken;\r
66 \r
67   /**\r
68    * Each entry in this array is an array of integers.  Each array\r
69    * of integers represents a sequence of tokens (by their ordinal\r
70    * values) that is expected at this point of the parse.\r
71    */\r
72   public int[][] expectedTokenSequences;\r
73 \r
74   /**\r
75    * This is a reference to the "tokenImage" array of the generated\r
76    * parser within which the parse error occurred.  This array is\r
77    * defined in the generated ...Constants interface.\r
78    */\r
79   public String[] tokenImage;\r
80 \r
81   /**\r
82    * It uses "currentToken" and "expectedTokenSequences" to generate a parse\r
83    * error message and returns it.  If this object has been created\r
84    * due to a parse error, and you do not catch it (it gets thrown\r
85    * from the parser) the correct error message\r
86    * gets displayed.\r
87    */\r
88   private static String initialise(Token currentToken,\r
89                            int[][] expectedTokenSequences,\r
90                            String[] tokenImage) {\r
91     String eol = System.getProperty("line.separator", "\n");\r
92     StringBuffer expected = new StringBuffer();\r
93     int maxSize = 0;\r
94     for (int i = 0; i < expectedTokenSequences.length; i++) {\r
95       if (maxSize < expectedTokenSequences[i].length) {\r
96         maxSize = expectedTokenSequences[i].length;\r
97       }\r
98       for (int j = 0; j < expectedTokenSequences[i].length; j++) {\r
99         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');\r
100       }\r
101       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {\r
102         expected.append("...");\r
103       }\r
104       expected.append(eol).append("    ");\r
105     }\r
106     String retval = "Encountered \"";\r
107     Token tok = currentToken.next;\r
108     for (int i = 0; i < maxSize; i++) {\r
109       if (i != 0) retval += " ";\r
110       if (tok.kind == 0) {\r
111         retval += tokenImage[0];\r
112         break;\r
113       }\r
114       retval += " " + tokenImage[tok.kind];\r
115       retval += " \"";\r
116       retval += add_escapes(tok.image);\r
117       retval += " \"";\r
118       tok = tok.next;\r
119     }\r
120     retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;\r
121     retval += "." + eol;\r
122     if (expectedTokenSequences.length == 1) {\r
123       retval += "Was expecting:" + eol + "    ";\r
124     } else {\r
125       retval += "Was expecting one of:" + eol + "    ";\r
126     }\r
127     retval += expected.toString();\r
128     return retval;\r
129   }\r
130 \r
131   /**\r
132    * The end of line string for this machine.\r
133    */\r
134   protected String eol = System.getProperty("line.separator", "\n");\r
135 \r
136   /**\r
137    * Used to convert raw characters to their escaped version\r
138    * when these raw version cannot be used as part of an ASCII\r
139    * string literal.\r
140    */\r
141   static String add_escapes(String str) {\r
142       StringBuffer retval = new StringBuffer();\r
143       char ch;\r
144       for (int i = 0; i < str.length(); i++) {\r
145         switch (str.charAt(i))\r
146         {\r
147            case 0 :\r
148               continue;\r
149            case '\b':\r
150               retval.append("\\b");\r
151               continue;\r
152            case '\t':\r
153               retval.append("\\t");\r
154               continue;\r
155            case '\n':\r
156               retval.append("\\n");\r
157               continue;\r
158            case '\f':\r
159               retval.append("\\f");\r
160               continue;\r
161            case '\r':\r
162               retval.append("\\r");\r
163               continue;\r
164            case '\"':\r
165               retval.append("\\\"");\r
166               continue;\r
167            case '\'':\r
168               retval.append("\\\'");\r
169               continue;\r
170            case '\\':\r
171               retval.append("\\\\");\r
172               continue;\r
173            default:\r
174               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {\r
175                  String s = "0000" + Integer.toString(ch, 16);\r
176                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));\r
177               } else {\r
178                  retval.append(ch);\r
179               }\r
180               continue;\r
181         }\r
182       }\r
183       return retval.toString();\r
184    }\r
185 \r
186 }\r
187 /* JavaCC - OriginalChecksum=32cb99e372d0c543d869005aedf4515b (do not edit this line) */\r