hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3360dd77e0dcc6484b29dde9ab0942f57b37212b
parent 413d17a737d263a696e620eb3d44077ecb58af58
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Thu,  2 Sep 2021 04:55:08 +0000

hare::lex: assume float on negative exponent

Fixes math/math.ha:52

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mhare/lex/+test.ha | 3++-
Mhare/lex/lex.ha | 4++--
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha @@ -254,7 +254,7 @@ fn loc(line: uint, col: uint) location = location { const in = "1e5 -1i32 9223372036854775809 1e2z 255u8 0o42u16\n" "0b1000101u32 0xDEADBEEFu64 -0b10i8 -5e0i16 -0o16i32\n" "0b00000010000001100000011100001111000000100000011000000111i64\n" - "13.37 13.37f32 13.37f64 6.022e23 1.616255e-35f64"; + "13.37 13.37f32 13.37f64 6.022e23 1.616255e-35f64 1e-1"; const expected: [_]token = [ (ltok::LIT_ICONST, 1e5i64, loc(1, 1)), (ltok::LIT_I32, -1i64, loc(1, 5)), @@ -273,6 +273,7 @@ fn loc(line: uint, col: uint) location = location { (ltok::LIT_F64, 13.37, loc(4, 16)), (ltok::LIT_FCONST, 6.022e23, loc(4, 25)), (ltok::LIT_F64, 1.616255e-35, loc(4, 34)), + (ltok::LIT_FCONST, 1e-1, loc(4, 50)), ]; lextest(in, expected); }; diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -439,10 +439,10 @@ fn lex_literal(lex: *lexer) (token | error) = { else if (suff == "i32") ltok::LIT_I32 else if (suff == "i64") ltok::LIT_I64 else if (suff == "i") ltok::LIT_INT - else if (suff == "" && !float) ltok::LIT_ICONST + else if (suff == "" && !float && exp >= 0) ltok::LIT_ICONST else if (suff == "f32") ltok::LIT_F32 else if (suff == "f64") ltok::LIT_F64 - else if (suff == "" && float) ltok::LIT_FCONST + else if (suff == "" && (float || exp < 0)) ltok::LIT_FCONST else return syntaxerr(loc, "invalid literal suffix"); let exp = if (exp < 0) switch (suff) {