-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for hexadecimal, octal and binary values #40
base: master
Are you sure you want to change the base?
Conversation
Of course, tests are green:
The only drawbacks of those notation are they are not compatible with PHP itself so we cannot directly add them to unit tests :/ We could support native syntax (as @Metalaka pointed out in #39 - http://php.net/manual/en/language.types.integer.php) but we would have to forbid constants/ids starting with digits so that we can use |
this seems weird, but just thinking out loud: what about allowing constants starting by any digit other than |
@CircleCode why not :)
Must also apply to ids then ;) |
maybe the question is "why did we want to allow constants starting by digits?" → the answer could help to chose one of the possible solutions amongst
|
When talking with @Hywan about supporting constants/ids starting with digits, I talked about "side effects": this one is a side-effects. It prevents us from implementing something interesting with a generic notation. My opinion is: let's close #39 and change constant names in #38 to something like |
I share @jubianchi 's opinion. |
See my comment in #39. |
@jubianchi @CircleCode 👍 |
👍 |
@@ -65,7 +65,7 @@ public function case_visitor_exhaustively() | |||
new Regex\Visitor\Isotropic( | |||
new LUT\Sampler\Random() | |||
), | |||
9 | |||
7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this value because with 9
the test suite generated more than a million expressions and I could not reach the end of the test... way tooooooo long :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with 8
which produce a reasonable test suite (~200 seconds AFAIR) but ended up getting the #42 bug :/
|
return $value; | ||
} elseif ('binary' === $token || 'hex' === $token || 'octal' === $token) { | ||
$out = (float) eval('return ' . $value . ';'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STOP THIS!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not work!!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only way to make them work is by trimming litterals before passing them to *dec : bindec(str_replace('0b', '', $binary));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do it. That's by far faster than using an eval
. Also, eval
is not caught by the opcode cache.
thanks for the review. Updates will be done today |
❤️ |
@hoaproject/hoackers need review :) |
Users can now use three new notations: * `0x539` for hexadecimal values * `0b101010` for binary values * `052` for octal values We can also mix them in expressions: ``` - ( 0b101010 * ( 0x539 / -052 ) ) / 100 ``` The result here will be `13.37`
) | ||
->then | ||
->object($compiler->parse($hexadecimalNumber)) | ||
->isInstanceOf('Hoa\Compiler\Llk\TreeNode') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the ID and the value of the token (resp. token
and hexadecimal
).
Same for subsequent test cases.
Review done. Need a little bit more corrections :-). |
And some test cases for overflows. |
Users can now use three new notations:
\x539
0x539
for hexadecimal values\b101010
0b101010
for binary values\052
052
for octal valuesWe can also mix them in expressions:
- ( \b101010 * ( \x539 / -\052 ) ) / 100
- ( 0b101010 * ( 0x539 / -052 ) ) / 100
The result here will be
13.37