Menu

[r251]: / trunk / src / TokenInfo.php  Maximize  Restore  History

Download this file

180 lines (169 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
if (! defined("T_ML_COMMENT")) {
define("T_ML_COMMENT", T_COMMENT);
}
define('T_NEW_LINE', 10000);
define('T_TAB', 10001);
define('T_SEMICOLON', 10002); // ;
define('T_BRACES_OPEN', 10003); // { To avoid confusion with T_CURLY_OPEN
define('T_BRACES_CLOSE', 10004); // }
define('T_PARENTHESIS_OPEN', 10005); // (
define('T_PARENTHESIS_CLOSE', 10006); // )
define('T_COMMA', 10007); // ,
define('T_EQUAL', 10008); // =
define('T_CONCAT', 10009); // .
define('T_COLON', 10010); // :
define('T_MINUS', 10011); // -
define('T_PLUS', 10012); // +
define('T_IS_GREATER', 10013); // >
define('T_IS_SMALLER', 10014); // <
define('T_MULTIPLY', 10015); // *
define('T_DIVIDE', 10016); // /
define('T_QUESTION_MARK', 10017); // ?
define('T_MODULO', 10018); // %
define('T_EXCLAMATION_MARK', 10019); // !
define('T_AMPERSAND', 10020); // %
define('T_SQUARE_BRACKET_OPEN', 10021); // [
define('T_SQUARE_BRACKET_CLOSE', 10022); // ]
define('T_AROBAS', 10023); // @
define('T_QUOTE', 10024); // " (only detected before and after a T_ENCAPSED_AND_WHITESPACE) otherwise should be included in T_CONSTANT_ENCAPSED_STRING
define('T_UNKNOWN', - 1);
/**
* TokenInfo class.
*
* This object is returned by the tokenizer.
*
* @package classes
* @SuppressWarnings checkUnusedVariables
*
*/
class TokenInfo {
/**
* The token ID.
*
* @var Integer
*/
var $id = null;
/**
* The token text.
*
* @var String
*/
var $text = null;
/**
* The position of the token in the file.
*
* @var Integer
*/
var $position = null;
/**
* The line number.
*
* @var Integer
*/
var $line;
/**
* Return a string representation of the token.
*
* @return String
*/
public function toString() {
$result = "";
$result .= "line : " . $this->line;
$result .= ", pos : " . $this->position;
$result .= ", id : " . $this->getName($this->id);
// Rename some special chars
$text = str_replace("\r\n", "\\r\\n", $this->text);
$text = str_replace("\r", "\\r", $text);
$text = str_replace("\n", "\\n", $text);
$result .= ", text : " . $text;
return $result;
}
/**
* Return the name of a token, including the NEW_LINE one.
*
* @return String the name of the token
*/
public function getName() {
switch ($this->id) {
case T_NEW_LINE:
$result = 'T_NEW_LINE';
break;
case T_TAB:
$result = 'T_TAB';
break;
case T_SEMICOLON:
$result = 'T_SEMICOLON';
break;
case T_BRACES_OPEN:
$result = 'T_BRACES_OPEN';
break;
case T_BRACES_CLOSE:
$result = 'T_BRACES_CLOSE';
break;
case T_PARENTHESIS_OPEN:
$result = 'T_PARENTHESIS_OPEN';
break;
case T_PARENTHESIS_CLOSE:
$result = 'T_PARENTHESIS_CLOSE';
break;
case T_COMMA:
$result = 'T_COMMA';
break;
case T_EQUAL:
$result = 'T_EQUAL';
break;
case T_CONCAT:
$result = 'T_CONCAT';
break;
case T_COLON:
$result = 'T_COLON';
break;
case T_MINUS:
$result = 'T_MINUS';
break;
case T_PLUS:
$result = 'T_PLUS';
break;
case T_IS_GREATER:
$result = 'T_IS_GREATER';
break;
case T_IS_SMALLER:
$result = 'T_IS_SMALLER';
break;
case T_MULTIPLY:
$result = 'T_MULTIPLY';
break;
case T_DIVIDE:
$result = 'T_DIVIDE';
break;
case T_QUESTION_MARK:
$result = 'T_QUESTION_MARK';
break;
case T_MODULO:
$result = 'T_MODULO';
break;
case T_EXCLAMATION_MARK:
$result = 'T_EXCLAMATION_MARK';
break;
case T_AMPERSAND:
$result = 'T_AMPERSAND';
break;
case T_SQUARE_BRACKET_OPEN:
$result = 'T_SQUARE_BRACKET_OPEN';
break;
case T_SQUARE_BRACKET_CLOSE:
$result = 'T_SQUARE_BRACKET_CLOSE';
break;
case T_AROBAS:
$result = 'T_AROBAS';
break;
case T_UNKNOWN:
$result = 'T_UNKNOWN';
break;
default:
$result = token_name($this->id);
}
return $result;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.