From 5ba6bd81e50f0d26d1e37271c005a06eee6aeb5a Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Tue, 20 Mar 2018 13:54:59 +0100 Subject: [PATCH] ConstExprParser: allow integers in bin, oct and hex format --- src/Lexer/Lexer.php | 2 +- tests/PHPStan/Parser/ConstExprParserTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Lexer/Lexer.php b/src/Lexer/Lexer.php index 47d9e05..98aaa9f 100644 --- a/src/Lexer/Lexer.php +++ b/src/Lexer/Lexer.php @@ -132,7 +132,7 @@ class Lexer self::TOKEN_PHPDOC_EOL => '\\r?+\\n[\\x09\\x20]*+(?:\\*(?!/))?', self::TOKEN_FLOAT => '(?:-?[0-9]++\\.[0-9]*+(?:e-?[0-9]++)?)|(?:-?[0-9]*+\\.[0-9]++(?:e-?[0-9]++)?)|(?:-?[0-9]++e-?[0-9]++)', - self::TOKEN_INTEGER => '-?[0-9]++', + self::TOKEN_INTEGER => '-?(?:(?:0b[0-1]++)|(?:0o[0-7]++)|(?:0x[0-9a-f]++)|(?:[0-9]++))', self::TOKEN_SINGLE_QUOTED_STRING => '\'(?:\\\\.|[^\'\\r\\n])*+\'', self::TOKEN_DOUBLE_QUOTED_STRING => '"(?:\\\\.|[^"\\r\\n])*+"', diff --git a/tests/PHPStan/Parser/ConstExprParserTest.php b/tests/PHPStan/Parser/ConstExprParserTest.php index 7951030..cf7b751 100644 --- a/tests/PHPStan/Parser/ConstExprParserTest.php +++ b/tests/PHPStan/Parser/ConstExprParserTest.php @@ -79,6 +79,26 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase '123', new ConstExprIntegerNode('123'), ], + [ + '0b0110101', + new ConstExprIntegerNode('0b0110101'), + ], + [ + '0o777', + new ConstExprIntegerNode('0o777'), + ], + [ + '0x7Fb4', + new ConstExprIntegerNode('0x7Fb4'), + ], + [ + '-0O777', + new ConstExprIntegerNode('-0O777'), + ], + [ + '-0X7Fb4', + new ConstExprIntegerNode('-0X7Fb4'), + ], [ '123.4', new ConstExprFloatNode('123.4'),