diff --git a/src/pk_compiler.c b/src/pk_compiler.c index 4d61016..ba054c2 100644 --- a/src/pk_compiler.c +++ b/src/pk_compiler.c @@ -773,8 +773,15 @@ static void lexToken(Compiler* compiler) { break; } - case '.': // TODO: ".5" should be a valid number. - setNextTwoCharToken(compiler, '.', TK_DOT, TK_DOTDOT); + case '.': + if (matchChar(compiler, '.')) { + setNextToken(compiler, TK_DOTDOT); // '..' + } else if (utilIsDigit(peekChar(compiler))) { + eatChar(compiler); // Consume the decimal point. + eatNumber(compiler); // Consume the rest of the number + } else { + setNextToken(compiler, TK_DOT); // '.' + } return; case '=': diff --git a/tests/lang/basics.pk b/tests/lang/basics.pk index e4b03c1..cb85921 100644 --- a/tests/lang/basics.pk +++ b/tests/lang/basics.pk @@ -103,6 +103,9 @@ for i in 0..1000 x = i; assert((x^=-1) == -i-1) end +assert(.5 == 0.5) +assert(.333 == .333) +assert(.1 + 1 == 1.1) # If we got here, that means all test were passed. print('All TESTS PASSED')