Allow floating point numbers without a zero before the decimal point
This commit is contained in:
parent
00e4de774f
commit
8840f06053
@ -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
2
unittests/float.chai
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
print(1.2)
|
||||||
|
print(.5)
|
2
unittests/float.txt
Normal file
2
unittests/float.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1.2
|
||||||
|
0.5
|
Loading…
x
Reference in New Issue
Block a user