01: /*
02: * gnu/regexp/REToken.java
03: * Copyright (C) 1998 Wes Biggs
04: *
05: * This library is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU Library General Public License as published
07: * by the Free Software Foundation; either version 2 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 Library General Public License for more details.
14: *
15: * You should have received a copy of the GNU Library 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.ByteArrayOutputStream;
23:
24: abstract class REToken {
25: // used by RETokenStart and RETokenEnd
26: static final String newline = System.getProperty("line.separator");
27:
28: protected REToken m_next = null;
29: protected REToken m_uncle = null;
30: protected int m_subIndex;
31:
32: protected REToken(int f_subIndex) {
33: m_subIndex = f_subIndex;
34: }
35:
36: int getMinimumLength() {
37: return 0;
38: }
39:
40: void setUncle(REToken f_uncle) {
41: m_uncle = f_uncle;
42: }
43:
44: abstract int[] match(CharIndexed input, int index, int eflags,
45: REMatch mymatch);
46:
47: protected int[] next(CharIndexed input, int index, int eflags,
48: REMatch mymatch) {
49: mymatch.end[m_subIndex] = index;
50: if (m_next == null) {
51: if (m_uncle == null) {
52: return new int[] { index };
53: } else {
54: if (m_uncle.match(input, index, eflags, mymatch) == null) {
55: return null;
56: } else {
57: return new int[] { index };
58: }
59: }
60: } else {
61: return m_next.match(input, index, eflags, mymatch);
62: }
63: }
64:
65: boolean chain(REToken next) {
66: m_next = next;
67: return true; // Token was accepted
68: }
69:
70: void dump(StringBuffer os) {
71: }
72:
73: void dumpAll(StringBuffer os) {
74: dump(os);
75: if (m_next != null)
76: m_next.dumpAll(os);
77: }
78: }
|