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 literal string terminal.
27: *
28: * @author Robert Grimm
29: * @version $Revision: 1.10 $
30: */
31: public class StringLiteral extends Terminal {
32:
33: /** The text. */
34: public final String text;
35:
36: /**
37: * Create a new string literal with the specified text.
38: *
39: * @param text The text.
40: */
41: public StringLiteral(String text) {
42: this .text = text;
43: }
44:
45: public Tag tag() {
46: return Tag.STRING_LITERAL;
47: }
48:
49: public int hashCode() {
50: return text.hashCode();
51: }
52:
53: public boolean equals(Object o) {
54: if (this == o)
55: return true;
56: if (!(o instanceof StringLiteral))
57: return false;
58: return text.equals(((StringLiteral) o).text);
59: }
60:
61: public void write(Appendable out) throws IOException {
62: out.append('\"');
63: Utilities.escape(text, out, Utilities.JAVA_ESCAPES);
64: out.append('\"');
65: }
66:
67: }
|