diff options
author | Juan J. Martinez <jjm@usebox.net> | 2024-05-26 21:29:17 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2024-05-26 21:29:17 +0100 |
commit | e755b9a23ff1bcce2ba256a7feed38e72aa58702 (patch) | |
tree | 075fde9c0d8c155f6bde2d7361b1b0b8699be7c2 | |
parent | ecb798fd7f9239cc21e89a777f5ffbaff48aabd7 (diff) | |
download | funco-e755b9a23ff1bcce2ba256a7feed38e72aa58702.tar.gz funco-e755b9a23ff1bcce2ba256a7feed38e72aa58702.zip |
Better parsing numbers
-rwxr-xr-x | funco | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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: |