From 8840f06053c95573c46455734a48c06a22868c5e Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 20 Aug 2009 14:50:13 +0000 Subject: [PATCH] Allow floating point numbers without a zero before the decimal point --- include/chaiscript/language/chaiscript_parser.hpp | 4 ++-- unittests/float.chai | 2 ++ unittests/float.txt | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 unittests/float.chai create mode 100644 unittests/float.txt diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 1609c91..8e66b02 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -140,7 +140,7 @@ namespace chaiscript */ bool Float_() { bool retval = false; - if ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) { + if ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) || (*input_pos == '.'))) { while ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) { ++input_pos; ++col; @@ -178,7 +178,7 @@ namespace chaiscript std::string::iterator start = input_pos; int prev_col = col; int prev_line = line; - if ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) { + if ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) || (*input_pos == '.')) ) { if (Float_()) { std::string match(start, input_pos); TokenPtr t(new Token(match, Token_Type::Float, filename, prev_line, prev_col, line, col)); diff --git a/unittests/float.chai b/unittests/float.chai new file mode 100644 index 0000000..f2fa6ea --- /dev/null +++ b/unittests/float.chai @@ -0,0 +1,2 @@ +print(1.2) +print(.5) diff --git a/unittests/float.txt b/unittests/float.txt new file mode 100644 index 0000000..73074be --- /dev/null +++ b/unittests/float.txt @@ -0,0 +1,2 @@ +1.2 +0.5