From a860a3f793f673be5cf4fce5e284828425af3f8f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Apr 2020 23:13:48 +0200 Subject: [PATCH] LibJS: Hack the lexer to allow numbers with decimals This is very hackish and should definitely be improved. :^) --- Libraries/LibJS/Lexer.cpp | 2 +- Libraries/LibJS/Token.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Libraries/LibJS/Lexer.cpp b/Libraries/LibJS/Lexer.cpp index 78ce72c135..0c4a36e416 100644 --- a/Libraries/LibJS/Lexer.cpp +++ b/Libraries/LibJS/Lexer.cpp @@ -229,7 +229,7 @@ Token Lexer::next() } } else if (isdigit(m_current_char)) { consume(); - while (isdigit(m_current_char)) { + while (m_current_char == '.' || isdigit(m_current_char)) { consume(); } token_type = TokenType::NumericLiteral; diff --git a/Libraries/LibJS/Token.cpp b/Libraries/LibJS/Token.cpp index 4e6ee1bb8b..22d898b3ae 100644 --- a/Libraries/LibJS/Token.cpp +++ b/Libraries/LibJS/Token.cpp @@ -52,9 +52,7 @@ const char* Token::name() const double Token::double_value() const { ASSERT(type() == TokenType::NumericLiteral); - // FIXME: need to parse double instead of int - bool ok; - return m_value.to_int(ok); + return strtod(String(m_value).characters(), nullptr); } String Token::string_value() const