delights / extended-tokens
Facilitate PHP code highlighting by changing T_STRING tokens to a more accurate representation
Requires
- php: ^7.3
Requires (Dev)
- ergebnis/phpstan-rules: ^0.15.0
- friendsofphp/php-cs-fixer: ^2.16.3
- pestphp/pest: ^0.2.2
- phpstan/phpstan: ^0.12.31
- phpstan/phpstan-strict-rules: ^0.12.2
- rector/rector: ^0.7.37
- symfony/var-dumper: ^5.1.2
- thecodingmachine/phpstan-strict-rules: ^0.12.0
This package is auto-updated.
Last update: 2021-11-18 07:43:01 UTC
README
**DEPRECATED use felixdorn/tin instead, the code was crap, please don't look at it. Also the T_FULL_NAMESPACE never worked well and PHP parses namespaces as one token now.
Extended Tokens
composer require delight/extended-tokens
This package is meant to facilitate PHP code highlighting by changing T_STRING tokens to a more accurate representation, like T_CLASS_NAME.
PHP ships by default with a Parser for PHP via the method token_get_all
This function returns an array of tokens that looks like this :
[ T_TOKENTYPE, "value", 42 // offset ];
Sometimes for tokens like {
, ;
, it just returns the literal string, not an array. g
This library change this, everything is an array, even those useless string.
Usage
use Delight\ExtendedTokens\ExtendedTokens; $parser = new ExtendedTokens(); $tokens = $parser->parse('code');
T_FULL_NAMESPACE
namespace A\B\C;
A\B\C
will be a T_FULL_NAMESPACE
T_CLASS_NAME
class A {}
A
will be a T_CLASS_NAME
new A;
A
will be a T_CLASS_NAME
T_FUNCTION_NAME
function hello() {}
hello
will be a T_FUNCTION_NAME
T_CONST_NAME
const E = 'F';
E
will be a T_CONST_NAME
T_EQUAL
$a = 1;
=
will be a T_EQUAL
T_CONCAT
$c = 'a' . 'b';
.
will be a T_CONCAT
T_VARIABLE after T_OBJECT_OPERATOR
$a->b;
b
will be a T_VARIABLE instead of a T_STRING
T_VARIABLE_TYPE
function world(string $name): World {}
string
will be a T_VARIABLE_TYPEWorld
will be a T_CLASS_NAME
T_TRUE and T_FALSE
true && false;
true
will be a T_TRUEfalse
will be a T_FALSE
T_REF
function (int &$index) {}
&
will be a T_REF
T_NEGATION
!true;
!
will be a T_NEGATION