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 binding of a grammar element to a variable.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.11 $
28: */
29: public class Binding extends UnaryOperator {
30:
31: /** The variable name. */
32: public String name;
33:
34: /**
35: * Create a new binding with the specified variable and element.
36: *
37: * @param name The variable name.
38: * @param element The bound element.
39: */
40: public Binding(String name, Element element) {
41: super (element);
42: this .name = name;
43: }
44:
45: public Tag tag() {
46: return Tag.BINDING;
47: }
48:
49: public int hashCode() {
50: return name.hashCode();
51: }
52:
53: public boolean equals(Object o) {
54: if (this == o)
55: return true;
56: if (!(o instanceof Binding))
57: return false;
58: Binding other = (Binding) o;
59: if (!name.equals(other.name))
60: return false;
61: return element.equals(other.element);
62: }
63:
64: public void write(Appendable out) throws IOException {
65: out.append(name);
66: out.append(':');
67: element.write(out);
68: }
69:
70: }
|