From e755b9a23ff1bcce2ba256a7feed38e72aa58702 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 26 May 2024 21:29:17 +0100 Subject: Better parsing numbers --- funco | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/funco b/funco index 0c27211..4462ab4 100755 --- a/funco +++ b/funco @@ -205,9 +205,15 @@ def tokenize(program: str) -> list[Token]: j += 1 lit = program[i:j] if lit[0].isdigit() and "." in lit: - yield Float(Location(line, col), float(lit)) + try: + yield Float(Location(line, col), float(lit)) + except Exception: + error(f"{Location(line, col)}: invalid Float {lit}") elif lit[0].isdigit(): - yield Int(Location(line, col), int(lit)) + try: + yield Int(Location(line, col), int(lit)) + except Exception: + error(f"{Location(line, col)}: invalid Int {lit}") elif lit in ("true", "false"): yield Boolean(Location(line, col), lit == "true") else: -- cgit v1.2.3