Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / labeling / parse / TokenMgrError.java @ 36624

History | View | Annotate | Download (5.37 KB)

1
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ibáñez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package org.gvsig.symbology.fmap.labeling.parse;
43

    
44
public class TokenMgrError extends Error
45
{
46
   /*
47
    * Ordinals for various reasons why an Error of this type can be thrown.
48
    */
49

    
50
   /**
51
    * Lexical error occurred.
52
    */
53
   static final int LEXICAL_ERROR = 0;
54

    
55
   /**
56
    * An attempt was made to create a second instance of a static token manager.
57
    */
58
   static final int STATIC_LEXER_ERROR = 1;
59

    
60
   /**
61
    * Tried to change to an invalid lexical state.
62
    */
63
   static final int INVALID_LEXICAL_STATE = 2;
64

    
65
   /**
66
    * Detected (and bailed out of) an infinite loop in the token manager.
67
    */
68
   static final int LOOP_DETECTED = 3;
69

    
70
   /**
71
    * Indicates the reason why the exception is thrown. It will have
72
    * one of the above 4 values.
73
    */
74
   int errorCode;
75

    
76
   /**
77
    * Replaces unprintable characters by their escaped (or unicode escaped)
78
    * equivalents in the given string
79
    */
80
   protected static final String addEscapes(String str) {
81
      StringBuffer retval = new StringBuffer();
82
      char ch;
83
      for (int i = 0; i < str.length(); i++) {
84
        switch (str.charAt(i))
85
        {
86
           case 0 :
87
              continue;
88
           case '\b':
89
              retval.append("\\b");
90
              continue;
91
           case '\t':
92
              retval.append("\\t");
93
              continue;
94
           case '\n':
95
              retval.append("\\n");
96
              continue;
97
           case '\f':
98
              retval.append("\\f");
99
              continue;
100
           case '\r':
101
              retval.append("\\r");
102
              continue;
103
           case '\"':
104
              retval.append("\\\"");
105
              continue;
106
           case '\'':
107
              retval.append("\\\'");
108
              continue;
109
           case '\\':
110
              retval.append("\\\\");
111
              continue;
112
           default:
113
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
114
                 String s = "0000" + Integer.toString(ch, 16);
115
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
116
              } else {
117
                 retval.append(ch);
118
              }
119
              continue;
120
        }
121
      }
122
      return retval.toString();
123
   }
124

    
125
   /**
126
    * Returns a detailed message for the Error when it is thrown by the
127
    * token manager to indicate a lexical error.
128
    * Parameters : 
129
    *    EOFSeen     : indicates if EOF caused the lexical error
130
    *    curLexState : lexical state in which this error occurred
131
    *    errorLine   : line number when the error occurred
132
    *    errorColumn : column number when the error occurred
133
    *    errorAfter  : prefix that was seen before this error occurred
134
    *    curchar     : the offending character
135
    * Note: You can customize the lexical error message by modifying this method.
136
    */
137
   protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
138
      return("Lexical error at line " +
139
           errorLine + ", column " +
140
           errorColumn + ".  Encountered: " +
141
           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
142
           "after : \"" + addEscapes(errorAfter) + "\"");
143
   }
144

    
145
   /**
146
    * You can also modify the body of this method to customize your error messages.
147
    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
148
    * of end-users concern, so you can return something like : 
149
    *
150
    *     "Internal Error : Please file a bug report .... "
151
    *
152
    * from this method for such cases in the release version of your parser.
153
    */
154
   public String getMessage() {
155
      return super.getMessage();
156
   }
157

    
158
   /*
159
    * Constructors of various flavors follow.
160
    */
161

    
162
   public TokenMgrError() {
163
   }
164

    
165
   public TokenMgrError(String message, int reason) {
166
      super(message);
167
      errorCode = reason;
168
   }
169

    
170
   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
171
      this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
172
   }
173
}