Allow floating point numbers without a zero before the decimal point

This commit is contained in:
Jonathan Turner 2009-08-20 14:50:13 +00:00
parent 00e4de774f
commit 8840f06053
3 changed files with 6 additions and 2 deletions

View File

@ -140,7 +140,7 @@ namespace chaiscript
*/ */
bool Float_() { bool Float_() {
bool retval = false; 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')) { while ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
++input_pos; ++input_pos;
++col; ++col;
@ -178,7 +178,7 @@ namespace chaiscript
std::string::iterator start = input_pos; std::string::iterator start = input_pos;
int prev_col = col; int prev_col = col;
int prev_line = line; 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_()) { if (Float_()) {
std::string match(start, input_pos); std::string match(start, input_pos);
TokenPtr t(new Token(match, Token_Type::Float, filename, prev_line, prev_col, line, col)); TokenPtr t(new Token(match, Token_Type::Float, filename, prev_line, prev_col, line, col));

2
unittests/float.chai Normal file
View File

@ -0,0 +1,2 @@
print(1.2)
print(.5)

2
unittests/float.txt Normal file
View File

@ -0,0 +1,2 @@
1.2
0.5