From 93f6933b3b0493644e40be87de9b1955457c7da4 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 7 Sep 2016 11:16:05 +0800 Subject: Parse - Fix up slightly iffy float edge cases --- src/parse/lex.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index f9d81f08..5fd10cf3 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -391,15 +391,13 @@ Token Lexer::getTokenInt() } if( ch == 'e' || ch == 'E' || ch == '.' ) { - if( num_mode != DEC ) - throw ParseError::Todo("Non-decimal floats"); - if( ch == '.' ) { ch = this->getc(); // Double/Triple Dot - if( ch == '.' ) { + if( ch == '.' ) + { if( this->getc() == '.') { this->m_next_token = Token(TOK_TRIPLE_DOT); } @@ -409,8 +407,9 @@ Token Lexer::getTokenInt() } return Token(val, CORETYPE_ANY); } - // Single dot - Still a float. (TODO) - else if( !ch.isdigit() ) + + // Single dot followed by a non-digit, could be a float or an integer with a method/field access + if( !ch.isdigit() ) { this->ungetc(); if( issym(ch) ) @@ -427,8 +426,13 @@ Token Lexer::getTokenInt() else { // Digit, continue + // NOTE: parseFloat assumes that the '.' has been consumed, and reads digits until it hits a non-digit and then parses exponents + // - Thus, continuing here and letting the below 'ungetc' push a digit back is correct. } } + if( num_mode != DEC ) + TODO(this->getPosition(), "Non-decimal floats"); + this->ungetc(); double fval = this->parseFloat(val); -- cgit v1.2.3