mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-05 20:26:53 +08:00
Numeric literal starts with decimal point implementation (Fix: #97)
This commit is contained in:
parent
c0f00f6cae
commit
fe45ba3485
@ -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 '=':
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user