1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 6.1 */
3 package org.simantics.databoard.parser;
5 /** Token Manager Error. */
6 public class TokenMgrError extends Error
10 * The version identifier for this Serializable class.
11 * Increment only if the <i>serialized</i> form of the
14 private static final long serialVersionUID = 1L;
17 * Ordinals for various reasons why an Error of this type can be thrown.
21 * Lexical error occurred.
23 public static final int LEXICAL_ERROR = 0;
26 * An attempt was made to create a second instance of a static token manager.
28 public static final int STATIC_LEXER_ERROR = 1;
31 * Tried to change to an invalid lexical state.
33 public static final int INVALID_LEXICAL_STATE = 2;
36 * Detected (and bailed out of) an infinite loop in the token manager.
38 public static final int LOOP_DETECTED = 3;
41 * Indicates the reason why the exception is thrown. It will have
42 * one of the above 4 values.
47 * Replaces unprintable characters by their escaped (or unicode escaped)
48 * equivalents in the given string
50 protected static final String addEscapes(String str) {
51 StringBuffer retval = new StringBuffer();
53 for (int i = 0; i < str.length(); i++) {
54 switch (str.charAt(i))
72 retval.append("\\\"");
75 retval.append("\\\'");
78 retval.append("\\\\");
81 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
82 String s = "0000" + Integer.toString(ch, 16);
83 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
90 return retval.toString();
94 * Returns a detailed message for the Error when it is thrown by the
95 * token manager to indicate a lexical error.
97 * EOFSeen : indicates if EOF caused the lexical error
98 * curLexState : lexical state in which this error occurred
99 * errorLine : line number when the error occurred
100 * errorColumn : column number when the error occurred
101 * errorAfter : prefix that was seen before this error occurred
102 * curchar : the offending character
103 * Note: You can customize the lexical error message by modifying this method.
105 protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) {
106 char curChar1 = (char)curChar;
107 return("Lexical error at line " +
108 errorLine + ", column " +
109 errorColumn + ". Encountered: " +
110 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + (int)curChar + "), ") +
111 "after : \"" + addEscapes(errorAfter) + "\"");
115 * You can also modify the body of this method to customize your error messages.
116 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
117 * of end-users concern, so you can return something like :
119 * "Internal Error : Please file a bug report .... "
121 * from this method for such cases in the release version of your parser.
123 public String getMessage() {
124 return super.getMessage();
128 * Constructors of various flavors follow.
131 /** No arg constructor. */
132 public TokenMgrError() {
135 /** Constructor with message and reason. */
136 public TokenMgrError(String message, int reason) {
141 /** Full Constructor. */
142 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) {
143 this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
146 /* JavaCC - OriginalChecksum=f476c1d882e6ae48270129e555d4889d (do not edit this line) */