01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2004-2007 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.parser;
20:
21: import java.io.IOException;
22:
23: /**
24: * A repeated grammar element.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.11 $
28: */
29: public class Repetition extends Quantification {
30:
31: /** Flag for whether the grammar element must appear at least once. */
32: public boolean once;
33:
34: /**
35: * Create a new repetition.
36: *
37: * @param once Flag for whether the grammar element must appear at least
38: * once.
39: * @param element The repeated grammar element.
40: */
41: public Repetition(boolean once, Element element) {
42: super (element);
43: this .once = once;
44: }
45:
46: public Tag tag() {
47: return Tag.REPETITION;
48: }
49:
50: public int hashCode() {
51: return element.hashCode();
52: }
53:
54: public boolean equals(Object o) {
55: if (this == o)
56: return true;
57: if (!(o instanceof Repetition))
58: return false;
59: Repetition other = (Repetition) o;
60: if (this .once != other.once)
61: return false;
62: return element.equals(other.element);
63: }
64:
65: public void write(Appendable out) throws IOException {
66: element.write(out);
67: if (once) {
68: out.append('+');
69: } else {
70: out.append('*');
71: }
72: }
73:
74: }
|