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