Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f9d449

Browse files
committed
feature #34028 [ExpressionLanguage][Lexer] Exponential format for number (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
2 parents 2931227 + 430ec32 commit 4f9d449

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Symfony/Component/ExpressionLanguage/Lexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function tokenize($expression)
4242
continue;
4343
}
4444

45-
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, 0, $cursor)) {
45+
if (preg_match('/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A', $expression, $match, 0, $cursor)) {
4646
// numbers
4747
$number = (float) $match[0]; // floats
4848
if (preg_match('/^[0-9]+$/', $match[0]) && $number <= PHP_INT_MAX) {

src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ public function getTokenizeData()
9797
new Token('punctuation', '[', 25),
9898
new Token('number', '4', 26),
9999
new Token('punctuation', ']', 27),
100+
new Token('operator', '-', 29),
101+
new Token('number', '1990', 31),
100102
],
101-
'(3 + 5) ~ foo("bar").baz[4]',
103+
'(3 + 5) ~ foo("bar").baz[4] - 1.99E+3',
102104
],
103105
[
104106
[new Token('operator', '..', 1)],

0 commit comments

Comments
 (0)