]> www.git.momoyon.org Git - lang.git/commitdiff
Parse string tokens.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 21 Oct 2024 08:07:38 +0000 (13:07 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 21 Oct 2024 08:07:38 +0000 (13:07 +0500)
main.py

diff --git a/main.py b/main.py
index 9dd8bd20bbb90749a795de74e0299075e30f0d85..129590e2e86ef64f459bde1f6a976adf5aa2e6b8 100644 (file)
--- a/main.py
+++ b/main.py
@@ -21,7 +21,7 @@ class Token:
         self.literal_string = literal_string
 
     def type_as_str(self):
-        assert(Token_Type.COUNT == 4, "Every enum value is not handled!")
+        assert Token_Type.COUNT == 5, "Every enum value is not handled!"
         if self.typ == Token_Type.IDENTIFIER: return "IDENTIFIER";
         if self.typ == Token_Type.NUMBER: return "NUMBER";
         if self.typ == Token_Type.SYMBOL: return "SYMBOL";
@@ -110,7 +110,18 @@ class Lexer:
         return symbol
 
     def consume_string(self) -> str:
+        c = self.current_char()
+        assert(c == '"')
+        # TODO: Does the string include the ""s? (for now it doesn't)
         string = ''
+        c = self.advance_char()
+        while c != '"':
+            string += c
+            c = self.advance_char()
+        # Remove " at the end
+        self.advance_char()
+
+        # dlog(f"String: '{string}'");
         return string
 
     def exhausted(self) -> bool: