token.php | ||||
|
||||
Coverage | ||||||||||
Classes | Functions / Methods | Lines | ||||||||
Total |
|
0.00% | 0 / 1 |
|
85.71% | 6 / 7 | CRAP |
|
64.71% | 11 / 17 |
Token |
|
0.00% | 0 / 1 |
|
85.71% | 6 / 7 | 14.40 |
|
64.71% | 11 / 17 |
__construct($type, $value = null) |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 4 / 4 | |||
gettype() |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 1 / 1 | |||
getValue() |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 1 / 1 | |||
setCurrLineNum($line) |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 2 / 2 | |||
setIncrLineNum($incr = 1) |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 2 / 2 | |||
getLineNum() |
|
100.00% | 1 / 1 | 1 |
|
100.00% | 1 / 1 | |||
getTypeName() |
|
0.00% | 0 / 1 | 20 |
|
0.00% | 0 / 6 |
1 : <?php 2 : /* 3 : Copyright 2008 Josh Heidenreich 4 : 5 : This file is part of Pelzini. 6 : 7 : Pelzini is free software: you can redistribute it and/or modify 8 : it under the terms of the GNU General Public License as published by 9 : the Free Software Foundation, either version 3 of the License, or 10 : (at your option) any later version. 11 : 12 : Pelzini is distributed in the hope that it will be useful, 13 : but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : GNU General Public License for more details. 16 : 17 : You should have received a copy of the GNU General Public License 18 : along with Pelzini. If not, see <http://www.gnu.org/licenses/>. 19 : */ 20 : 21 : 22 : /** 23 : * This class is used to represent a token that has been tokenised using a Lexer. (e.g. the JavascriptLexer) 24 : * These tokens are used to create various ParserItems, by passing them to an Analyser (e.g. the JavascriptAnalyser) 25 : **/ 26 : class Token 27 : { 28 : private $type; 29 : private $value; 30 : private $linenum; 31 : 32 : static $curr_linenum = 1; 33 : 34 : public function __construct($type, $value = null) 35 : { 36 6 : $this->linenum = self::$curr_linenum; 37 6 : $this->type = $type; 38 6 : $this->value = $value; 39 6 : } 40 : 41 : 42 : /** 43 : * Gets the type of this token 44 : **/ 45 : public function gettype() 46 : { 47 6 : return $this->type; 48 : } 49 : 50 : 51 : /** 52 : * Gets the value of this token 53 : **/ 54 : public function getValue() 55 : { 56 6 : return $this->value; 57 : } 58 : 59 : 60 : /** 61 : * Set the "current" line number. New tokens have a line number set to this figure. 62 : * 63 : * @param int $line 64 : **/ 65 : public static function setCurrLineNum($line) 66 : { 67 3 : self::$curr_linenum = $line; 68 3 : } 69 : 70 : 71 : /** 72 : * Increment the "current" line number. New tokens have a line number set to this figure. 73 : **/ 74 : public static function setIncrLineNum($incr = 1) 75 : { 76 3 : self::$curr_linenum += $incr; 77 3 : } 78 : 79 : 80 : /** 81 : * Gets the line number this toekn 82 : **/ 83 : public function getLineNum() 84 : { 85 3 : return $this->linenum; 86 : } 87 : 88 : 89 : /** 90 : * Uses some PHP cleverness to get the name of the constant 91 : * that this token referres to. 92 : * Good for debugging 93 : **/ 94 : public function getTypeName() 95 : { 96 0 : $constants = get_defined_constants(); 97 0 : foreach ($constants as $name => $val) { 98 0 : if (strncmp($name, 'TOKEN_', 6) === 0 and $val == $this->type) { 99 0 : return $name; 100 : } 101 0 : } 102 : 103 0 : return null; 104 : } 105 : 106 : } |
Generated by PHP_CodeCoverage 1.1.2 using PHP 5.4.39-0+deb7u2 and PHPUnit 3.6.10 at Fri Sep 11 11:35:19 WIT 2015. |