01: //
02: // Generated by JTB 1.2.2
03: //
04:
05: package xtc.lang.javacc.syntaxtree;
06:
07: import java.util.*;
08:
09: /**
10: * Represents a single token in the grammar. If the "-tk" option
11: * is used, also contains a Vector of preceding special tokens.
12: */
13: @SuppressWarnings("unchecked")
14: public class NodeToken implements Node {
15: public NodeToken(String s) {
16: this (s, -1, -1, -1, -1, -1);
17: }
18:
19: public NodeToken(String s, int kind, int beginLine,
20: int beginColumn, int endLine, int endColumn) {
21: tokenImage = s;
22: specialTokens = null;
23: this .kind = kind;
24: this .beginLine = beginLine;
25: this .beginColumn = beginColumn;
26: this .endLine = endLine;
27: this .endColumn = endColumn;
28: }
29:
30: public NodeToken getSpecialAt(int i) {
31: if (specialTokens == null)
32: throw new NoSuchElementException("No specials in token");
33: return (NodeToken) specialTokens.elementAt(i);
34: }
35:
36: public int numSpecials() {
37: if (specialTokens == null)
38: return 0;
39: return specialTokens.size();
40: }
41:
42: public void addSpecial(NodeToken s) {
43: if (specialTokens == null)
44: specialTokens = new Vector();
45: specialTokens.addElement(s);
46: }
47:
48: public void trimSpecials() {
49: if (specialTokens == null)
50: return;
51: specialTokens.trimToSize();
52: }
53:
54: public String toString() {
55: return tokenImage;
56: }
57:
58: public String withSpecials() {
59: if (specialTokens == null)
60: return tokenImage;
61:
62: StringBuffer buf = new StringBuffer();
63:
64: for (Enumeration e = specialTokens.elements(); e
65: .hasMoreElements();)
66: buf.append(e.nextElement().toString());
67:
68: buf.append(tokenImage);
69: return buf.toString();
70: }
71:
72: public void accept(xtc.lang.javacc.visitor.Visitor v) {
73: v.visit(this );
74: }
75:
76: public Object accept(xtc.lang.javacc.visitor.ObjectVisitor v,
77: Object argu) {
78: return v.visit(this , argu);
79: }
80:
81: public String tokenImage;
82:
83: // Stores a list of NodeTokens
84: public Vector specialTokens;
85:
86: // -1 for these ints means no position info is available.
87: public int beginLine, beginColumn, endLine, endColumn;
88:
89: // Equal to the JavaCC token "kind" integer.
90: // -1 if not available.
91: public int kind;
92: }
|