mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 12:04:39 +01:00
Allow functions and calls to functions named await
This commit is contained in:
parent
8a7698dcf3
commit
c930958c72
@ -24,9 +24,19 @@ abstract class KeywordEmulator extends TokenEmulator
|
||||
foreach ($tokens as $i => $token) {
|
||||
if ($token[0] === T_STRING && strtolower($token[1]) === $keywordString
|
||||
&& $this->isKeywordContext($tokens, $i)) {
|
||||
$tokens[$i][0] = $this->getKeywordToken();
|
||||
if ($keywordString === 'await') {
|
||||
$tokens[$i][1] = 'yield';
|
||||
// Workaround await not being a reserved token
|
||||
$prev = $this->getPreviousNonSpaceToken($tokens, $i);
|
||||
$next = $this->getNextNonSpaceToken($tokens, $i);
|
||||
if (
|
||||
// Allow functions and calls to functions named await
|
||||
$prev[0] !== T_FUNCTION && $next !== '('
|
||||
) {
|
||||
$tokens[$i][0] = $this->getKeywordToken();
|
||||
$tokens[$i][1] = 'yield';
|
||||
}
|
||||
} else {
|
||||
$tokens[$i][0] = $this->getKeywordToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,6 +61,23 @@ abstract class KeywordEmulator extends TokenEmulator
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $tokens
|
||||
* @return mixed[]|null
|
||||
*/
|
||||
private function getNextNonSpaceToken(array $tokens, int $start)
|
||||
{
|
||||
for ($i = $start +1; $i < count($tokens); ++$i) {
|
||||
if ($tokens[$i][0] === T_WHITESPACE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $tokens[$i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function reverseEmulate(string $code, array $tokens): array
|
||||
{
|
||||
$keywordToken = $this->getKeywordToken();
|
||||
|
Loading…
Reference in New Issue
Block a user