1 19 20 package gnu.regexp; 21 import java.io.Serializable ; 22 import java.util.BitSet ; 23 24 34 35 public final class RESyntax implements Serializable { 36 static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator"); 37 38 private static final String SYNTAX_IS_FINAL = RE.getLocalizedMessage("syntax.final"); 39 40 private BitSet bits; 41 42 private boolean isFinal = false; 44 45 private String lineSeparator = DEFAULT_LINE_SEPARATOR; 46 47 49 52 public static final int RE_BACKSLASH_ESCAPE_IN_LISTS = 0; 53 54 57 public static final int RE_BK_PLUS_QM = 1; 58 59 62 public static final int RE_CHAR_CLASSES = 2; 63 64 68 public static final int RE_CONTEXT_INDEP_ANCHORS = 3; 69 70 74 public static final int RE_CONTEXT_INDEP_OPS = 4; 75 76 81 public static final int RE_CONTEXT_INVALID_OPS = 5; 82 83 86 public static final int RE_DOT_NEWLINE = 6; 87 88 91 public static final int RE_DOT_NOT_NULL = 7; 92 93 96 public static final int RE_INTERVALS = 8; 97 98 102 public static final int RE_LIMITED_OPS = 9; 103 104 107 public static final int RE_NEWLINE_ALT = 10; 109 112 public static final int RE_NO_BK_BRACES = 11; 113 114 117 public static final int RE_NO_BK_PARENS = 12; 118 119 122 public static final int RE_NO_BK_REFS = 13; 123 124 127 public static final int RE_NO_BK_VBAR = 14; 128 129 132 public static final int RE_NO_EMPTY_RANGES = 15; 133 134 138 public static final int RE_UNMATCHED_RIGHT_PAREN_ORD = 16; 139 140 143 public static final int RE_HAT_LISTS_NOT_NEWLINE = 17; 144 145 148 public static final int RE_STINGY_OPS = 18; 149 150 153 public static final int RE_CHAR_CLASS_ESCAPES = 19; 154 155 158 public static final int RE_PURE_GROUPING = 20; 159 160 164 public static final int RE_LOOKAHEAD = 21; 165 166 169 public static final int RE_STRING_ANCHORS = 22; 170 171 174 public static final int RE_COMMENTS = 23; 175 176 179 public static final int RE_CHAR_CLASS_ESC_IN_LISTS = 24; 180 181 private static final int BIT_TOTAL = 25; 182 183 187 public static final RESyntax RE_SYNTAX_AWK; 188 189 193 public static final RESyntax RE_SYNTAX_ED; 194 195 199 public static final RESyntax RE_SYNTAX_EGREP; 200 201 205 public static final RESyntax RE_SYNTAX_EMACS; 206 207 211 public static final RESyntax RE_SYNTAX_GREP; 212 213 217 public static final RESyntax RE_SYNTAX_POSIX_AWK; 218 219 223 public static final RESyntax RE_SYNTAX_POSIX_BASIC; 224 225 229 public static final RESyntax RE_SYNTAX_POSIX_EGREP; 230 231 235 public static final RESyntax RE_SYNTAX_POSIX_EXTENDED; 236 237 241 public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_BASIC; 242 243 247 public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_EXTENDED; 248 249 253 public static final RESyntax RE_SYNTAX_SED; 254 255 259 public static final RESyntax RE_SYNTAX_PERL4; 260 261 266 public static final RESyntax RE_SYNTAX_PERL4_S; 268 272 public static final RESyntax RE_SYNTAX_PERL5; 273 274 279 public static final RESyntax RE_SYNTAX_PERL5_S; 280 281 static { 282 284 RE_SYNTAX_EMACS = new RESyntax().makeFinal(); 285 286 RESyntax RE_SYNTAX_POSIX_COMMON = new RESyntax() 287 .set(RE_CHAR_CLASSES) 288 .set(RE_DOT_NEWLINE) 289 .set(RE_DOT_NOT_NULL) 290 .set(RE_INTERVALS) 291 .set(RE_NO_EMPTY_RANGES) 292 .makeFinal(); 293 294 RE_SYNTAX_POSIX_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON) 295 .set(RE_BK_PLUS_QM) 296 .makeFinal(); 297 298 RE_SYNTAX_POSIX_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON) 299 .set(RE_CONTEXT_INDEP_ANCHORS) 300 .set(RE_CONTEXT_INDEP_OPS) 301 .set(RE_NO_BK_BRACES) 302 .set(RE_NO_BK_PARENS) 303 .set(RE_NO_BK_VBAR) 304 .set(RE_UNMATCHED_RIGHT_PAREN_ORD) 305 .makeFinal(); 306 307 RE_SYNTAX_AWK = new RESyntax() 308 .set(RE_BACKSLASH_ESCAPE_IN_LISTS) 309 .set(RE_DOT_NOT_NULL) 310 .set(RE_NO_BK_PARENS) 311 .set(RE_NO_BK_REFS) 312 .set(RE_NO_BK_VBAR) 313 .set(RE_NO_EMPTY_RANGES) 314 .set(RE_UNMATCHED_RIGHT_PAREN_ORD) 315 .makeFinal(); 316 317 RE_SYNTAX_POSIX_AWK = new RESyntax(RE_SYNTAX_POSIX_EXTENDED) 318 .set(RE_BACKSLASH_ESCAPE_IN_LISTS) 319 .makeFinal(); 320 321 RE_SYNTAX_GREP = new RESyntax() 322 .set(RE_BK_PLUS_QM) 323 .set(RE_CHAR_CLASSES) 324 .set(RE_HAT_LISTS_NOT_NEWLINE) 325 .set(RE_INTERVALS) 326 .set(RE_NEWLINE_ALT) 327 .makeFinal(); 328 329 RE_SYNTAX_EGREP = new RESyntax() 330 .set(RE_CHAR_CLASSES) 331 .set(RE_CONTEXT_INDEP_ANCHORS) 332 .set(RE_CONTEXT_INDEP_OPS) 333 .set(RE_HAT_LISTS_NOT_NEWLINE) 334 .set(RE_NEWLINE_ALT) 335 .set(RE_NO_BK_PARENS) 336 .set(RE_NO_BK_VBAR) 337 .makeFinal(); 338 339 RE_SYNTAX_POSIX_EGREP = new RESyntax(RE_SYNTAX_EGREP) 340 .set(RE_INTERVALS) 341 .set(RE_NO_BK_BRACES) 342 .makeFinal(); 343 344 345 346 RE_SYNTAX_ED = new RESyntax(RE_SYNTAX_POSIX_BASIC) 347 .makeFinal(); 348 349 RE_SYNTAX_SED = new RESyntax(RE_SYNTAX_POSIX_BASIC) 350 .makeFinal(); 351 352 RE_SYNTAX_POSIX_MINIMAL_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON) 353 .set(RE_LIMITED_OPS) 354 .makeFinal(); 355 356 358 359 RE_SYNTAX_POSIX_MINIMAL_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON) 360 .set(RE_CONTEXT_INDEP_ANCHORS) 361 .set(RE_CONTEXT_INVALID_OPS) 362 .set(RE_NO_BK_BRACES) 363 .set(RE_NO_BK_PARENS) 364 .set(RE_NO_BK_REFS) 365 .set(RE_NO_BK_VBAR) 366 .set(RE_UNMATCHED_RIGHT_PAREN_ORD) 367 .makeFinal(); 368 369 370 371 RE_SYNTAX_PERL4 = new RESyntax() 372 .set(RE_BACKSLASH_ESCAPE_IN_LISTS) 373 .set(RE_CONTEXT_INDEP_ANCHORS) 374 .set(RE_CONTEXT_INDEP_OPS) .set(RE_INTERVALS) 376 .set(RE_NO_BK_BRACES) 377 .set(RE_NO_BK_PARENS) 378 .set(RE_NO_BK_VBAR) 379 .set(RE_NO_EMPTY_RANGES) 380 .set(RE_CHAR_CLASS_ESCAPES) .makeFinal(); 382 383 RE_SYNTAX_PERL4_S = new RESyntax(RE_SYNTAX_PERL4) 384 .set(RE_DOT_NEWLINE) 385 .makeFinal(); 386 387 RE_SYNTAX_PERL5 = new RESyntax(RE_SYNTAX_PERL4) 388 .set(RE_PURE_GROUPING) .set(RE_STINGY_OPS) .set(RE_LOOKAHEAD) .set(RE_STRING_ANCHORS) .set(RE_CHAR_CLASS_ESC_IN_LISTS) .set(RE_COMMENTS) .makeFinal(); 395 396 RE_SYNTAX_PERL5_S = new RESyntax(RE_SYNTAX_PERL5) 397 .set(RE_DOT_NEWLINE) 398 .makeFinal(); 399 } 400 401 405 public RESyntax() { 406 bits = new BitSet (BIT_TOTAL); 407 } 408 409 417 public RESyntax makeFinal() { 418 isFinal = true; 419 return this; 420 } 421 422 426 public RESyntax(RESyntax other) { 427 bits = (BitSet ) other.bits.clone(); 428 } 429 430 433 public boolean get(int index) { 434 return bits.get(index); 435 } 436 437 443 public RESyntax set(int index) { 444 if (isFinal) throw new IllegalAccessError (SYNTAX_IS_FINAL); 445 bits.set(index); 446 return this; 447 } 448 449 455 public RESyntax clear(int index) { 456 if (isFinal) throw new IllegalAccessError (SYNTAX_IS_FINAL); 457 bits.clear(index); 458 return this; 459 } 460 461 478 public RESyntax setLineSeparator(String aSeparator) { 479 if (isFinal) throw new IllegalAccessError (SYNTAX_IS_FINAL); 480 lineSeparator = aSeparator; 481 return this; 482 } 483 484 488 public String getLineSeparator() { 489 return lineSeparator; 490 } 491 } 492 | Popular Tags |