01: /*
02: * gnu/regexp/REToken.java
03: * Copyright (C) 1998-2001 Wes Biggs
04: *
05: * This library is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU Lesser General Public License as published
07: * by the Free Software Foundation; either version 2.1 of the License, or
08: * (at your option) any later version.
09: *
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.io.Serializable;
23:
24: abstract class REToken implements Serializable {
25:
26: protected REToken next = null;
27: protected REToken uncle = null;
28: protected int subIndex;
29:
30: protected REToken(int subIndex) {
31: this .subIndex = subIndex;
32: }
33:
34: int getMinimumLength() {
35: return 0;
36: }
37:
38: void setUncle(REToken anUncle) {
39: uncle = anUncle;
40: }
41:
42: /** Returns true if the match succeeded, false if it failed. */
43: abstract boolean match(CharIndexed input, REMatch mymatch);
44:
45: /** Returns true if the rest of the tokens match, false if they fail. */
46: protected boolean next(CharIndexed input, REMatch mymatch) {
47: if (next == null) {
48: if (uncle == null) {
49: return true;
50: } else {
51: return uncle.match(input, mymatch);
52: }
53: } else {
54: return next.match(input, mymatch);
55: }
56: }
57:
58: boolean chain(REToken token) {
59: next = token;
60: return true; // Token was accepted
61: }
62:
63: abstract void dump(StringBuffer os);
64:
65: void dumpAll(StringBuffer os) {
66: dump(os);
67: if (next != null)
68: next.dumpAll(os);
69: }
70: }
|