00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.antlr.runtime;
00029
00037 public class ClassicToken implements Token {
00038 protected String text;
00039 protected int type;
00040 protected int line;
00041 protected int charPositionInLine;
00042 protected int channel=DEFAULT_CHANNEL;
00043
00045 protected int index;
00046
00047 public ClassicToken(int type) {
00048 this.type = type;
00049 }
00050
00051 public ClassicToken(Token oldToken) {
00052 text = oldToken.getText();
00053 type = oldToken.getType();
00054 line = oldToken.getLine();
00055 charPositionInLine = oldToken.getCharPositionInLine();
00056 channel = oldToken.getChannel();
00057 }
00058
00059 public ClassicToken(int type, String text) {
00060 this.type = type;
00061 this.text = text;
00062 }
00063
00064 public ClassicToken(int type, String text, int channel) {
00065 this.type = type;
00066 this.text = text;
00067 this.channel = channel;
00068 }
00069
00070 public int getType() {
00071 return type;
00072 }
00073
00074 public void setLine(int line) {
00075 this.line = line;
00076 }
00077
00078 public String getText() {
00079 return text;
00080 }
00081
00082 public void setText(String text) {
00083 this.text = text;
00084 }
00085
00086 public int getLine() {
00087 return line;
00088 }
00089
00090 public int getCharPositionInLine() {
00091 return charPositionInLine;
00092 }
00093
00094 public void setCharPositionInLine(int charPositionInLine) {
00095 this.charPositionInLine = charPositionInLine;
00096 }
00097
00098 public int getChannel() {
00099 return channel;
00100 }
00101
00102 public void setChannel(int channel) {
00103 this.channel = channel;
00104 }
00105
00106 public void setType(int type) {
00107 this.type = type;
00108 }
00109
00110 public int getTokenIndex() {
00111 return index;
00112 }
00113
00114 public void setTokenIndex(int index) {
00115 this.index = index;
00116 }
00117
00118 public CharStream getInputStream() {
00119 return null;
00120 }
00121
00122 public void setInputStream(CharStream input) {
00123 }
00124
00125 public String toString() {
00126 String channelStr = "";
00127 if ( channel>0 ) {
00128 channelStr=",channel="+channel;
00129 }
00130 String txt = getText();
00131 if ( txt!=null ) {
00132 txt = txt.replaceAll("\n","\\\\n");
00133 txt = txt.replaceAll("\r","\\\\r");
00134 txt = txt.replaceAll("\t","\\\\t");
00135 }
00136 else {
00137 txt = "<no text>";
00138 }
00139 return "[@"+getTokenIndex()+",'"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]";
00140 }
00141 }