Skip to content

Commit

Permalink
[ExpressionLanguage][Lexer] Exponential format for number
Browse files Browse the repository at this point in the history
Exponential format has been added for numbers.
Ex: 1.99E+3 === 1990,
Ex: expression (1 + 1.99E+3) = 1991
  • Loading branch information
tigr1991 committed Oct 18, 2019
1 parent 594e7ae commit 430ec32
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 430ec32

Please sign in to comment.