resolve darcs stupidity
[org.ibex.core.git] / src / gnu / regexp / REException.java
1 /*
2  *  gnu/regexp/REException.java
3  *  Copyright (C) 1998-2001 Wes Biggs
4  *
5  *  This library is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU Lesser General Public License as published
7  *  by the Free Software Foundation; either version 2.1 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 package gnu.regexp;
21
22 import java.text.MessageFormat;
23
24 /**
25  * This is the regular expression exception class.  An exception of this type
26  * defines the three attributes:
27  * <OL>
28  * <LI> A descriptive message of the error.
29  * <LI> An integral type code equivalent to one of the statically
30  *      defined symbols listed below.
31  * <LI> The approximate position in the input string where the error
32  *      occurred.
33  * </OL>
34  *
35  * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
36  */
37
38 public class REException extends Exception {
39   private int type;
40   private int pos;
41
42   // Error conditions from GNU regcomp(3) manual
43
44   /**
45    * Error flag.
46    * Invalid use of repetition operators such  as  using
47    * `*' as the first character.
48    */
49   public static final int REG_BADRPT  =  1;
50
51   /**
52    * Error flag.
53    * Invalid use of back reference operator.
54    */
55   public static final int REG_BADBR   =  2;
56
57   /**
58    * Error flag.
59    * Un-matched brace interval operators.
60    */
61   public static final int REG_EBRACE  =  3;
62
63   /**
64    * Error flag.
65    * Un-matched bracket list operators.
66    */
67   public static final int REG_EBRACK  =  4;
68
69   /**
70    * Error flag.
71    * Invalid  use  of the range operator, eg. the ending
72    * point of the range occurs  prior  to  the  starting
73    * point.
74    */
75   public static final int REG_ERANGE  =  5;
76
77   /**
78    * Error flag.
79    * Unknown character class name. <B>Not implemented</B>.
80    */
81   public static final int REG_ECTYPE  =  6;
82
83   /**
84    * Error flag.
85    * Un-matched parenthesis group operators.
86    */
87   public static final int REG_EPAREN  =  7;
88
89   /**
90    * Error flag.
91    * Invalid back reference to a subexpression.
92    */
93   public static final int REG_ESUBREG =  8;
94
95   /**
96    * Error flag.
97    * Non specific error. <B>Not implemented</B>.
98    */
99   public static final int REG_EEND    =  9;
100
101   /**
102    * Error flag.
103    * Invalid escape sequence. <B>Not implemented</B>.
104    */
105   public static final int REG_ESCAPE  = 10;
106
107   /**
108    * Error flag.
109    * Invalid  use  of pattern operators such as group or list.
110    */
111   public static final int REG_BADPAT  = 11;
112
113   /**
114    * Error flag.
115    * Compiled  regular  expression  requires  a  pattern
116    * buffer larger than 64Kb. <B>Not implemented</B>.
117    */
118   public static final int REG_ESIZE   = 12;
119
120   /**
121    * Error flag.
122    * The regex routines ran out of memory. <B>Not implemented</B>.
123    */
124   public static final int REG_ESPACE  = 13;
125
126   REException(String msg, int type, int position) { 
127     super(msg); 
128     this.type = type;
129     this.pos = position;
130   }
131
132   /**
133    * Returns the type of the exception, one of the constants listed above.
134    */
135
136   public int getType() {
137     return type;
138   }
139
140   /**
141    * Returns the position, relative to the string or character array being
142    * compiled, where the error occurred.  This position is generally the point
143    * where the error was detected, not necessarily the starting index of
144    * a bad subexpression.
145    */
146   public int getPosition() {
147     return pos;
148   }
149
150   /**
151    * Reports the descriptive message associated with this exception
152    * as well as its index position in the string or character array
153    * being compiled.
154    */
155   public String getMessage() {
156     Object[] args = {new Integer(pos)};
157     StringBuffer sb = new StringBuffer();
158     String prefix = RE.getLocalizedMessage("error.prefix");
159     sb.append(MessageFormat.format(prefix, args));
160     sb.append('\n');
161     sb.append(super.getMessage());
162     return sb.toString();
163   }
164 }