ConstExprParser: allow integers in bin, oct and hex format

This commit is contained in:
Jan Tvrdik 2018-03-20 13:54:59 +01:00
parent 97be1de71b
commit 5ba6bd81e5
2 changed files with 21 additions and 1 deletions

View File

@ -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])*+"',

View File

@ -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'),