]> www.git.momoyon.org Git - lang.git/commitdiff
# TODO: Handle floating point numbers
authorahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 16 Nov 2024 18:24:42 +0000 (23:24 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Sat, 16 Nov 2024 18:25:28 +0000 (23:25 +0500)
main.momo
main.py
tests/08-floating-point-numbers.momo [new file with mode: 0644]
tests/08-floating-point-numbers.momo.test [new file with mode: 0644]

index 356da7336f2c47a070597d0f8a0b5d34c5e908aa..f1e547bdd114b1a621df25503e14b054741955de 100644 (file)
--- a/main.momo
+++ b/main.momo
@@ -1,6 +1,3 @@
-() {} [] ->
-- + / * %
-= !
->= > < <= != ==
-, : ; .
-
+69.0
+100.15134324
+420.11
diff --git a/main.py b/main.py
index 1b00a67e367e19591943c99acf1f9250f84bfbda..41783239bbbbf20c18823135c3f0d38b0a491757 100644 (file)
--- a/main.py
+++ b/main.py
@@ -177,12 +177,19 @@ class Parser:
         assert self.current_char().isdigit(), "Called consume_number() at the wrong character!"
         number: str = self.consume_char()
 
-        # TODO: Handle floating point numbers
         # TODO: Handle numbers in other formats (Eg, binary, hexadecimal, etc)
         number_loc: Loc = Loc(self.filename, self.line, self.row())
-
-        while self.current_char().isdigit() and not self.eof():
-            number += self.consume_char()
+        dot_handled: bool = False
+
+        while (self.current_char().isdigit() or self.current_char() == '.') and not self.eof():
+            if self.current_char() == '.':
+                if dot_handled:
+                    self.fatal("Number can only have one dots!")
+                number += self.consume_char()
+                dot_handled = True
+            else:
+                assert self.current_char().isdigit(), "This should never happen"
+                number += self.consume_char()
 
         return (number, number_loc)
 
diff --git a/tests/08-floating-point-numbers.momo b/tests/08-floating-point-numbers.momo
new file mode 100644 (file)
index 0000000..f1e547b
--- /dev/null
@@ -0,0 +1,3 @@
+69.0
+100.15134324
+420.11
diff --git a/tests/08-floating-point-numbers.momo.test b/tests/08-floating-point-numbers.momo.test
new file mode 100644 (file)
index 0000000..a254459
--- /dev/null
@@ -0,0 +1,4 @@
+"Token (Number, '69.0', ./tests/08-floating-point-numbers.momo:1:1)"
+"Token (Number, '100.15134324', ./tests/08-floating-point-numbers.momo:2:1)"
+"Token (Number, '420.11', ./tests/08-floating-point-numbers.momo:3:1)"
+'None'