aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-05-26 21:29:17 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-05-26 21:29:17 +0100
commite755b9a23ff1bcce2ba256a7feed38e72aa58702 (patch)
tree075fde9c0d8c155f6bde2d7361b1b0b8699be7c2
parentecb798fd7f9239cc21e89a777f5ffbaff48aabd7 (diff)
downloadfunco-e755b9a23ff1bcce2ba256a7feed38e72aa58702.tar.gz
funco-e755b9a23ff1bcce2ba256a7feed38e72aa58702.zip
Better parsing numbers
-rwxr-xr-xfunco10
1 files 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: