system-dashboard
/
vendor
/
phpdocumentor
/
reflection
/
src
/
phpDocumentor
/
Reflection
/
Lexer.php
Lexer.php in System Dashboard 2.8.3, at vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/Lexer.php
| 1 | <?php |
| 2 | /** |
| 3 | * phpDocumentor |
| 4 | * |
| 5 | * PHP Version 5.3 |
| 6 | * |
| 7 | * @author Mike van Riel <mike.vanriel@naenius.com> |
| 8 | * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) |
| 9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 10 | * @link http://phpdoc.org |
| 11 | */ |
| 12 | |
| 13 | namespace phpDocumentor\Reflection; |
| 14 | |
| 15 | use PhpParser\Lexer as BaseLexer; |
| 16 | use PhpParser\Parser; |
| 17 | |
| 18 | /** |
| 19 | * Custom lexer for phpDocumentor. |
| 20 | * |
| 21 | * phpDocumentor has a custom Lexer for PHP-Parser because it needs |
| 22 | * unmodified value for Scalar variables instead of an interpreted version. |
| 23 | * |
| 24 | * If the interpreted version was to be used then the XML interpretation would |
| 25 | * fail because of special characters. |
| 26 | * |
| 27 | * @author Mike van Riel <mike.vanriel@naenius.com> |
| 28 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 29 | * @link http://phpdoc.org |
| 30 | */ |
| 31 | class Lexer extends BaseLexer |
| 32 | { |
| 33 | /** |
| 34 | * Retrieves the next token and determines the associated attributes and |
| 35 | * returns the token id. |
| 36 | * |
| 37 | * @param string $value |
| 38 | * @param string[] $startAttributes |
| 39 | * @param string[] $endAttributes |
| 40 | * |
| 41 | * @return int |
| 42 | */ |
| 43 | public function getNextToken( |
| 44 | &$value = null, |
| 45 | &$startAttributes = null, |
| 46 | &$endAttributes = null |
| 47 | ) { |
| 48 | $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes); |
| 49 | |
| 50 | if ($this->isTokenScalar($tokenId)) { |
| 51 | // store original value because the value itself will be interpreted |
| 52 | // by PHP_Parser and we want the unformatted value |
| 53 | $endAttributes['originalValue'] = $value; |
| 54 | } |
| 55 | |
| 56 | return $tokenId; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns whether the given token id is a scalar that will be interpreted |
| 61 | * by PHP-Parser. |
| 62 | * |
| 63 | * @param int $tokenId The id to check, must match a \PhpParser_Parser::T_* |
| 64 | * constant. |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | protected function isTokenScalar($tokenId) |
| 69 | { |
| 70 | return $tokenId == Parser::T_CONSTANT_ENCAPSED_STRING |
| 71 | || $tokenId == Parser::T_LNUMBER |
| 72 | || $tokenId == Parser::T_DNUMBER; |
| 73 | } |
| 74 | } |
| 75 |