From 4e12d320eb240fe245faaba164e40d0d430e36b7 Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Tue, 12 Apr 2022 18:10:51 +0800 Subject: [PATCH] fix the wrong regex pattern of scientific notation (#794) Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com> --- src/parser/scanner.lex | 5 ++--- src/parser/test/ScannerTest.cpp | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index b451467e0b4..4ebf867ce4e 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -409,9 +409,8 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}* return parseDecimal(); } -{DEC}*\.{DEC}+ | -{DEC}+\.{DEC}* | -{DEC}*\.{DEC}*{EXP} | +{DEC}*\.{DEC}+{EXP}? | +{DEC}+\.{DEC}*{EXP}? | {DEC}+{EXP} { return parseDouble(); } diff --git a/src/parser/test/ScannerTest.cpp b/src/parser/test/ScannerTest.cpp index a841ca5fbd1..68e822ec40d 100644 --- a/src/parser/test/ScannerTest.cpp +++ b/src/parser/test/ScannerTest.cpp @@ -546,6 +546,9 @@ TEST(Scanner, Basic) { CHECK_SEMANTIC_VALUE("123.", TokenType::DOUBLE, 123.), CHECK_SEMANTIC_VALUE(".123", TokenType::DOUBLE, 0.123), CHECK_SEMANTIC_VALUE("123.456", TokenType::DOUBLE, 123.456), + CHECK_SEMANTIC_VALUE("1.2e1", TokenType::DOUBLE, 12.0), + CHECK_SEMANTIC_VALUE("1.e2", TokenType::DOUBLE, 100.0), + CHECK_SEMANTIC_VALUE(".2e3", TokenType::DOUBLE, 200.0), CHECK_SEMANTIC_VALUE("0x7FFFFFFFFFFFFFFF", TokenType::INTEGER, 0x7FFFFFFFFFFFFFFFL), CHECK_SEMANTIC_VALUE("0x007FFFFFFFFFFFFFFF", TokenType::INTEGER, 0x007FFFFFFFFFFFFFFFL),