/interpreter/tags/at2dist170907/src/edu/vub/util/regexp/REException.java

http://ambienttalk.googlecode.com/ · Java · 182 lines · 39 code · 23 blank · 120 comment · 0 complexity · e5636ad15b053d3234b99d58b95b332a MD5 · raw file

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