Skip to content

Commit 5ba6bd8

Browse files
committed
ConstExprParser: allow integers in bin, oct and hex format
1 parent 97be1de commit 5ba6bd8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

‎src/Lexer/Lexer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function initialize()
132132
self::TOKEN_PHPDOC_EOL => '\\r?+\\n[\\x09\\x20]*+(?:\\*(?!/))?',
133133

134134
self::TOKEN_FLOAT => '(?:-?[0-9]++\\.[0-9]*+(?:e-?[0-9]++)?)|(?:-?[0-9]*+\\.[0-9]++(?:e-?[0-9]++)?)|(?:-?[0-9]++e-?[0-9]++)',
135-
self::TOKEN_INTEGER => '-?[0-9]++',
135+
self::TOKEN_INTEGER => '-?(?:(?:0b[0-1]++)|(?:0o[0-7]++)|(?:0x[0-9a-f]++)|(?:[0-9]++))',
136136
self::TOKEN_SINGLE_QUOTED_STRING => '\'(?:\\\\.|[^\'\\r\\n])*+\'',
137137
self::TOKEN_DOUBLE_QUOTED_STRING => '"(?:\\\\.|[^"\\r\\n])*+"',
138138

‎tests/PHPStan/Parser/ConstExprParserTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ public function provideParseData(): array
7979
'123',
8080
new ConstExprIntegerNode('123'),
8181
],
82+
[
83+
'0b0110101',
84+
new ConstExprIntegerNode('0b0110101'),
85+
],
86+
[
87+
'0o777',
88+
new ConstExprIntegerNode('0o777'),
89+
],
90+
[
91+
'0x7Fb4',
92+
new ConstExprIntegerNode('0x7Fb4'),
93+
],
94+
[
95+
'-0O777',
96+
new ConstExprIntegerNode('-0O777'),
97+
],
98+
[
99+
'-0X7Fb4',
100+
new ConstExprIntegerNode('-0X7Fb4'),
101+
],
82102
[
83103
'123.4',
84104
new ConstExprFloatNode('123.4'),

0 commit comments

Comments
 (0)