001 //
002 // Generated by JTB 1.3.2
003 //
004
005 package jtb.syntaxtree;
006
007 import java.util.*;
008 /**
009 * Represents a single token in the grammar. If the "-tk" option
010 * is used, also contains a Vector of preceding special tokens.
011 */
012 public class NodeToken implements Node {
013 static final long serialVersionUID = 20050923L;
014
015 public NodeToken(String s) {
016 this(s, -1, -1, -1, -1, -1);
017 }
018
019 public NodeToken(String s, int kind, int beginLine, int beginColumn, int endLine, int endColumn) {
020 tokenImage = s;
021 specialTokens = null;
022 this.kind = kind;
023 this.beginLine = beginLine;
024 this.beginColumn = beginColumn;
025 this.endLine = endLine;
026 this.endColumn = endColumn;
027 }
028
029 public NodeToken getSpecialAt(int i) {
030 if ( specialTokens == null )
031 throw new java.util.NoSuchElementException("No specials in token");
032 return specialTokens.elementAt(i);
033 }
034
035 public int numSpecials() {
036 if ( specialTokens == null ) return 0;
037 return specialTokens.size();
038 }
039
040 public void addSpecial(NodeToken s) {
041 if ( specialTokens == null ) specialTokens = new Vector<NodeToken>();
042 specialTokens.addElement(s);
043 s.setParent(this);
044 }
045
046 public void trimSpecials() {
047 if ( specialTokens == null ) return;
048 specialTokens.trimToSize();
049 }
050
051 public String toString() { return tokenImage; }
052
053 public String withSpecials() {
054 if ( specialTokens == null )
055 return tokenImage;
056
057 StringBuffer buf = new StringBuffer();
058
059 for ( Enumeration<NodeToken> e = specialTokens.elements(); e.hasMoreElements(); )
060 buf.append(e.nextElement().toString());
061
062 buf.append(tokenImage);
063 return buf.toString();
064 }
065
066 public void accept(jtb.visitor.Visitor v) {
067 v.visit(this);
068 }
069 public <R,A> R accept(jtb.visitor.GJVisitor<R,A> v, A argu) {
070 return v.visit(this,argu);
071 }
072 public <R> R accept(jtb.visitor.GJNoArguVisitor<R> v) {
073 return v.visit(this);
074 }
075 public <A> void accept(jtb.visitor.GJVoidVisitor<A> v, A argu) {
076 v.visit(this,argu);
077 }
078
079 public void setParent(Node n) { parent = n; }
080 public Node getParent() { return parent; }
081
082 private Node parent;
083 public String tokenImage;
084
085 // Stores a list of NodeTokens
086 public Vector<NodeToken> specialTokens;
087
088 // -1 for these ints means no position info is available.
089 public int beginLine, beginColumn, endLine, endColumn;
090
091 // Equal to the JavaCC token "kind" integer.
092 // -1 if not available.
093 public int kind;
094 }