Numeric literal starts with decimal point implementation (Fix: #97)

This commit is contained in:
Tiago Cavalcante Trindade 2021-06-22 16:21:19 -03:00 committed by GitHub
parent c0f00f6cae
commit fe45ba3485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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 '=':

View File

@ -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')