[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 class TokenConst{ 4 public static $EOR_TOKEN_TYPE = 1; 5 6 /** imaginary tree navigation type; traverse "get child" link */ 7 public static $DOWN = 2; 8 /** imaginary tree navigation type; finish with a child list */ 9 public static $UP = 3; 10 11 public static $MIN_TOKEN_TYPE;// = UP+1; 12 13 public static $EOF;// = CharStream.EOF; 14 public static $EOF_TOKEN;// = new CommonToken(EOF); 15 16 public static $INVALID_TOKEN_TYPE = 0; 17 public static $INVALID_TOKEN;// = new CommonToken(INVALID_TOKEN_TYPE); 18 19 /** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR 20 * will avoid creating a token for this symbol and try to fetch another. 21 */ 22 public static $SKIP_TOKEN;// = new CommonToken(INVALID_TOKEN_TYPE); 23 24 /** All tokens go to the parser (unless skip() is called in that rule) 25 * on a particular "channel". The parser tunes to a particular channel 26 * so that whitespace etc... can go to the parser on a "hidden" channel. 27 */ 28 public static $DEFAULT_CHANNEL = 0; 29 30 /** Anything on different channel than DEFAULT_CHANNEL is not parsed 31 * by parser. 32 */ 33 public static $HIDDEN_CHANNEL = 99; 34 } 35 36 37 interface Token{ 38 } 39 40 41 class CommonToken implements Token { 42 43 44 function __construct(){ 45 46 } 47 48 public static function forInput($input=null, $type, $channel=0, $start=0, $stop=0) { 49 $ct = new CommonToken(); 50 $ct->charPositionInLine=-1; 51 $ct->input = $input; 52 $ct->type = $type; 53 $ct->channel = $channel; 54 $ct->start = $start; 55 $ct->stop = $stop; 56 return $ct; 57 } 58 59 public static function forType($type){ 60 return CommonToken::forInput($input=null, $type); 61 } 62 63 public static function forTypeAndText($type, $text) { 64 $ct = new CommonToken(); 65 $ct->type = $type; 66 $ct->channel = TokenConst::$DEFAULT_CHANNEL; 67 $ct->text = $text; 68 return $ct; 69 } 70 /* 71 public CommonToken(Token oldToken) { 72 text = oldToken.getText(); 73 type = oldToken.getType(); 74 line = oldToken.getLine(); 75 index = oldToken.getTokenIndex(); 76 charPositionInLine = oldToken.getCharPositionInLine(); 77 channel = oldToken.getChannel(); 78 if ( oldToken instanceof CommonToken ) { 79 start = ((CommonToken)oldToken).start; 80 stop = ((CommonToken)oldToken).stop; 81 } 82 } 83 */ 84 public function getType() { 85 return $this->type; 86 } 87 88 public function setLine($line) { 89 $this->line = $this->line; 90 } 91 92 public function getText() { 93 if ( $this->text!=null ) { 94 return $this->text; 95 } 96 if ( $this->input==null ) { 97 return null; 98 } 99 $this->text = $this->input->substring($this->start,$this->stop); 100 return $this->text; 101 } 102 103 /** Override the text for this token. getText() will return this text 104 * rather than pulling from the buffer. Note that this does not mean 105 * that start/stop indexes are not valid. It means that that input 106 * was converted to a new string in the token object. 107 */ 108 public function setText($text) { 109 $this->text = $this->text; 110 } 111 112 public function getLine() { 113 return $this->line; 114 } 115 116 public function getCharPositionInLine() { 117 return $this->charPositionInLine; 118 } 119 120 public function setCharPositionInLine($charPositionInLine) { 121 $this->charPositionInLine = $this->charPositionInLine; 122 } 123 124 public function getChannel() { 125 return $this->channel; 126 } 127 128 public function setChannel($channel) { 129 $this->channel = $this->channel; 130 } 131 132 public function setType($type) { 133 $this->type = $this->type; 134 } 135 136 public function getStartIndex() { 137 return $this->start; 138 } 139 140 public function setStartIndex($start) { 141 $this->start = $this->start; 142 } 143 144 public function getStopIndex() { 145 return $this->stop; 146 } 147 148 public function setStopIndex($stop) { 149 $this->stop = $this->stop; 150 } 151 152 public function getTokenIndex() { 153 return $this->index; 154 } 155 156 public function setTokenIndex($index) { 157 $this->index = $this->index; 158 } 159 160 public function getInputStream() { 161 return $this->input; 162 } 163 164 public function setInputStream($input) { 165 $this->input = $this->input; 166 } 167 168 public function toString() { 169 $channelStr = ""; 170 if ( $this->channel>0 ) { 171 $channelStr=",channel=".$this->channel; 172 } 173 $txt = $this->getText(); 174 if ( $txt!=null ) { 175 $txt = str_replace("\n",'\n', $txt); 176 $txt = str_replace("\r",'\r', $txt); 177 $txt = str_replace("\t",'\t', $txt); 178 } 179 else { 180 $txt = "<no text>"; 181 } 182 return "[@".$this->getTokenIndex().",".$this->start.":".$this->stop."='".$txt."',<".$this->type.">".$channelStr.",".$this->line.":".$this->getCharPositionInLine()."]"; 183 } 184 185 public function __toString(){ 186 return $this->toString(); 187 } 188 } 189 190 TokenConst::$DEFAULT_CHANNEL=0; 191 TokenConst::$INVALID_TOKEN_TYPE=0; 192 193 TokenConst::$EOF = CharStreamConst::$EOF; 194 TokenConst::$EOF_TOKEN = CommonToken::forType(TokenConst::$EOF); 195 196 TokenConst::$INVALID_TOKEN_TYPE = 0; 197 TokenConst::$INVALID_TOKEN = CommonToken::forType(TokenConst::$INVALID_TOKEN_TYPE); 198 /** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR 199 * will avoid creating a token for this symbol and try to fetch another. 200 */ 201 TokenConst::$SKIP_TOKEN = CommonToken::forType(TokenConst::$INVALID_TOKEN_TYPE); 202 203 /** All tokens go to the parser (unless skip() is called in that rule) 204 * on a particular "channel". The parser tunes to a particular channel 205 * so that whitespace etc... can go to the parser on a "hidden" channel. 206 */ 207 TokenConst::$DEFAULT_CHANNEL = 0; 208 209 /** Anything on different channel than DEFAULT_CHANNEL is not parsed 210 * by parser. 211 */ 212 TokenConst::$HIDDEN_CHANNEL = 99; 213 214 215 216 TokenConst::$MIN_TOKEN_TYPE = TokenConst::$UP+1; 217 218 219 220 221 222 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |