Skip to content

Commit

Permalink
feature #34028 [ExpressionLanguage][Lexer] Exponential format for num…
Browse files Browse the repository at this point in the history
…ber (tigr1991)

This PR was merged into the 4.4 branch.

Discussion
----------

[ExpressionLanguage][Lexer] Exponential format for number

Exponential format has been added for numbers.
Ex: 1.99E+3 === 1990,
Ex: expression (1 + 1.99E+3) = 1991

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Exponential format has been added for numbers.
Ex: 1.99E+3 === 1990,
Expressions:
0.1e+2 = 10
1e-2 = 0.01
(1 + 1.99E+3) = 1991
and etc...

Commits
-------

430ec32 [ExpressionLanguage][Lexer] Exponential format for number
  • Loading branch information
fabpot committed Oct 22, 2019
2 parents 2931227 + 430ec32 commit 4f9d449
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/ExpressionLanguage/Lexer.php
Expand Up @@ -42,7 +42,7 @@ public function tokenize($expression)
continue;
}

if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, 0, $cursor)) {
if (preg_match('/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A', $expression, $match, 0, $cursor)) {
// numbers
$number = (float) $match[0]; // floats
if (preg_match('/^[0-9]+$/', $match[0]) && $number <= PHP_INT_MAX) {
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php
Expand Up @@ -97,8 +97,10 @@ public function getTokenizeData()
new Token('punctuation', '[', 25),
new Token('number', '4', 26),
new Token('punctuation', ']', 27),
new Token('operator', '-', 29),
new Token('number', '1990', 31),
],
'(3 + 5) ~ foo("bar").baz[4]',
'(3 + 5) ~ foo("bar").baz[4] - 1.99E+3',
],
[
[new Token('operator', '..', 1)],
Expand Down

0 comments on commit 4f9d449

Please sign in to comment.