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