mirror of
https://github.com/php/php-src.git
synced 2025-08-17 22:48:57 +02:00

we basically added a mechanism to store the token stream during parsing and exposed the entire parser stack on the tokenizer extension through an opt in flag: token_get_all($src, TOKEN_PARSE). this change allows easy future language enhancements regarding context aware parsing & scanning without further maintance on the tokenizer extension while solves known inconsistencies "parseless" tokenizer extension has when it handles `__halt_compiler()` presence.
68 lines
1,014 B
PHP
68 lines
1,014 B
PHP
--TEST--
|
|
Semi reserved words support: class const
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
|
|
--FILE--
|
|
<?php
|
|
$tokens = token_get_all('<?php
|
|
class SomeClass {
|
|
const CONST = 1;
|
|
const CONTINUE = (self::CONST + 1);
|
|
const ARRAY = [1, self::CONTINUE => [3, 4], 5];
|
|
}
|
|
', TOKEN_PARSE);
|
|
|
|
array_walk($tokens, function($tk) {
|
|
if(is_array($tk)) {
|
|
if(($t = token_name($tk[0])) == 'T_WHITESPACE') return;
|
|
echo "L{$tk[2]}: ".$t." {$tk[1]}", PHP_EOL;
|
|
}
|
|
else echo $tk, PHP_EOL;
|
|
});
|
|
|
|
echo "Done";
|
|
|
|
?>
|
|
--EXPECTF--
|
|
L1: T_OPEN_TAG <?php
|
|
|
|
L2: T_CLASS class
|
|
L2: T_STRING SomeClass
|
|
{
|
|
L3: T_CONST const
|
|
L3: T_STRING CONST
|
|
=
|
|
L3: T_LNUMBER 1
|
|
;
|
|
L4: T_CONST const
|
|
L4: T_STRING CONTINUE
|
|
=
|
|
(
|
|
L4: T_STRING self
|
|
L4: T_DOUBLE_COLON ::
|
|
L4: T_STRING CONST
|
|
+
|
|
L4: T_LNUMBER 1
|
|
)
|
|
;
|
|
L5: T_CONST const
|
|
L5: T_STRING ARRAY
|
|
=
|
|
[
|
|
L5: T_LNUMBER 1
|
|
,
|
|
L5: T_STRING self
|
|
L5: T_DOUBLE_COLON ::
|
|
L5: T_STRING CONTINUE
|
|
L5: T_DOUBLE_ARROW =>
|
|
[
|
|
L5: T_LNUMBER 3
|
|
,
|
|
L5: T_LNUMBER 4
|
|
]
|
|
,
|
|
L5: T_LNUMBER 5
|
|
]
|
|
;
|
|
}
|
|
Done
|