Menu

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

Download this file

107 lines (95 with data), 2.6 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
<?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() {
$tagNames = array(
T_NEW_LINE => 'T_NEW_LINE',
T_TAB => 'T_TAB',
T_SEMICOLON => 'T_SEMICOLON',
T_BRACES_OPEN => 'T_BRACES_OPEN',
T_BRACES_CLOSE => 'T_BRACES_CLOSE',
T_PARENTHESIS_OPEN => 'T_PARENTHESIS_OPEN',
T_PARENTHESIS_CLOSE => 'T_PARENTHESIS_CLOSE',
T_COMMA => 'T_COMMA',
T_EQUAL => 'T_EQUAL',
T_CONCAT => 'T_CONCAT',
T_COLON => 'T_COLON',
T_MINUS => 'T_MINUS',
T_PLUS => 'T_PLUS',
T_IS_GREATER => 'T_IS_GREATER',
T_IS_SMALLER => 'T_IS_SMALLER',
T_MULTIPLY => 'T_MULTIPLY',
T_DIVIDE => 'T_DIVIDE',
T_QUESTION_MARK => 'T_QUESTION_MARK',
T_MODULO => 'T_MODULO',
T_EXCLAMATION_MARK => 'T_EXCLAMATION_MARK',
T_AMPERSAND => 'T_AMPERSAND',
T_SQUARE_BRACKET_OPEN => 'T_SQUARE_BRACKET_OPEN',
T_SQUARE_BRACKET_CLOSE => 'T_SQUARE_BRACKET_CLOSE',
T_AROBAS => 'T_AROBAS',
T_UNKNOWN => 'T_UNKNOWN',
T_DOLLAR => 'T_DOLLAR',
);
if (isset($tagNames[$this->id])) {
$result = $tagNames[$this->id];
} else {
$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.