001//
002// Generated by JTB 1.1.2
003//
004
005package jtb.cparser.syntaxtree;
006
007import 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 */
012public 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   public NodeToken(String s, int kind, int beginLine, int beginColumn, int endLine, int endColumn) {
019      tokenImage = s;
020      specialTokens = null;
021      this.kind = kind;
022      this.beginLine = beginLine;
023      this.beginColumn = beginColumn;
024      this.endLine = endLine;
025      this.endColumn = endColumn;
026   }
027
028   public NodeToken getSpecialAt(int i) {
029      if ( specialTokens == null )
030         throw new NoSuchElementException("No specials in token");
031      return specialTokens.elementAt(i);
032   }
033
034   public int numSpecials() {
035      if ( specialTokens == null ) return 0;
036      return specialTokens.size();
037   }
038
039   public void addSpecial(NodeToken s) {
040      if ( specialTokens == null ) specialTokens = new Vector<NodeToken>();
041      specialTokens.addElement(s);
042   }
043
044   public void trimSpecials() {
045      if ( specialTokens == null ) return;
046      specialTokens.trimToSize();
047   }
048
049   public String toString()     { return tokenImage; }
050
051   public String withSpecials() {
052      if ( specialTokens == null )
053          return tokenImage;
054
055       StringBuffer buf = new StringBuffer();
056
057       for ( Enumeration<NodeToken> e = specialTokens.elements(); e.hasMoreElements(); )
058          buf.append(e.nextElement().toString());
059
060       buf.append(tokenImage);
061       return buf.toString();
062   }
063
064   public void accept(jtb.cparser.visitor.Visitor v) {
065      v.visit(this);
066   }
067
068   public String tokenImage;
069
070   // Stores a list of NodeTokens
071   public Vector<NodeToken> specialTokens;
072
073   // -1 for these ints means no position info is available.
074   public int beginLine, beginColumn, endLine, endColumn;
075
076   // Equal to the JavaCC token "kind" integer.
077   // -1 if not available.
078   public int kind;
079}