Menu

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

Download this file

151 lines (141 with data), 2.9 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
<?php
namespace PHPCheckstyle;
/**
* 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.