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