Make check in numeric literal separator emulator more precise

a) Don't check for !== false, preg_match() return 0 if there is
no match. This effectively means that the check was always true.
b) Check for hex characters only if there's an 0x prefix. 1_1 is
very likely a numeric separator, but a_b might well be part of
an identifier.

Fixes #639.
This commit is contained in:
Nikita Popov 2020-02-09 22:48:28 +01:00
parent 64f4d5b619
commit a2443aaefa

View File

@ -21,7 +21,8 @@ final class NumericLiteralSeparatorEmulator implements TokenEmulatorInterface
return false;
}
return preg_match('~[0-9a-f]_[0-9a-f]~i', $code) !== false;
return preg_match('~[0-9]_[0-9]~', $code)
|| preg_match('~0x[0-9a-f]+_[0-9a-f]~i', $code);
}
public function emulate(string $code, array $tokens): array