001// 002// Generated by JTB 1.3.2 003// 004 005package jtb.syntaxtree; 006 007import java.util.*; 008// Represents a single token in the grammar. If the "-tk" option 009// is used, also contains a Vector of preceding special tokens. 010public class NodeToken implements Node { 011 // This was added after running jtb to remove serializable warning. 012 static final long serialVersionUID = 20150406L; 013 014 public NodeToken(String s) { 015 this(s, -1, -1, -1, -1, -1); } 016 017 public NodeToken(String s, int kind, int beginLine, int beginColumn, int endLine, int endColumn) { 018 tokenImage = s; 019 specialTokens = null; 020 this.kind = kind; 021 this.beginLine = beginLine; 022 this.beginColumn = beginColumn; 023 this.endLine = endLine; 024 this.endColumn = endColumn; 025 } 026 027 public NodeToken getSpecialAt(int i) { 028 if ( specialTokens == null ) 029 throw new java.util.NoSuchElementException("No specials in token"); 030 return specialTokens.elementAt(i); 031 } 032 033 public int numSpecials() { 034 if ( specialTokens == null ) return 0; 035 return specialTokens.size(); 036 } 037 038 public void addSpecial(NodeToken s) { 039 if ( specialTokens == null ) specialTokens = new Vector<NodeToken>(); 040 specialTokens.addElement(s); 041 s.setParent(this); 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.visitor.Visitor v) { 065 v.visit(this); 066 } 067 public <R,A> R accept(jtb.visitor.GJVisitor<R,A> v, A argu) { 068 return v.visit(this,argu); 069 } 070 public <R> R accept(jtb.visitor.GJNoArguVisitor<R> v) { 071 return v.visit(this); 072 } 073 public <A> void accept(jtb.visitor.GJVoidVisitor<A> v, A argu) { 074 v.visit(this,argu); 075 } 076 077 public void setParent(Node n) { parent = n; } 078 public Node getParent() { return parent; } 079 080 private Node parent; 081 public String tokenImage; 082 083 // Stores a list of NodeTokens 084 public Vector<NodeToken> specialTokens; 085 086 // -1 for these ints means no position info is available. 087 public int beginLine, beginColumn, endLine, endColumn; 088 089 // Equal to the JavaCC token "kind" integer. 090 // -1 if not available. 091 public int kind; 092} 093