]> www.git.momoyon.org Git - lang.git/commitdiff
Can Parse '#'.
authorahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 18 Nov 2024 16:01:41 +0000 (21:01 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Mon, 18 Nov 2024 16:02:39 +0000 (21:02 +0500)
- No longer append 'None' to tokens.
- Updated tests.

.gitignore
main.py
tests/02-string.momo.test
tests/03-whitespaced-string.momo.test
tests/04-identifier.momo.test
tests/05-multiple-identifiers.momo.test
tests/06-single-char-symbols.momo.test
tests/07-numbers.momo.test
tests/08-floating-point-numbers.momo.test

index 73d41de6105853f7ba00a396131aeba9c3acd973..a6e9d26f625b90a4913b0082813d8336d0d73aa4 100644 (file)
@@ -1 +1,2 @@
 test.sh
+lang.sh
diff --git a/main.py b/main.py
index 41783239bbbbf20c18823135c3f0d38b0a491757..2c802f7ef118976b2cd0d759b83457e563cbdab5 100644 (file)
--- a/main.py
+++ b/main.py
@@ -60,6 +60,7 @@ class TokenType(IntEnum):
     COLON = auto()
     SEMICOLON = auto()
     DOT = auto()
+    HASH = auto()
     LEFT_SQUARE_BRACE = auto()
     RIGHT_SQUARE_BRACE = auto()
 
@@ -91,6 +92,7 @@ token_type_as_str_map: { TokenType : str } = {
     TokenType.COLON                : "Colon",
     TokenType.SEMICOLON            : "Semicolon",
     TokenType.DOT                  : "Dot",
+    TokenType.HASH                 : "Hash",
     TokenType.LEFT_SQUARE_BRACE    : "Left Square Brace",
     TokenType.RIGHT_SQUARE_BRACE   : "Right Square Brace",
     TokenType.NUMBER               : "Number"
@@ -291,6 +293,9 @@ class Parser:
         elif c == '.':
             loc = Loc(self.filename, self.line, self.row())
             return Token(TokenType.DOT, self.consume_char(), loc)
+        elif c == '#':
+            loc = Loc(self.filename, self.line, self.row())
+            return Token(TokenType.HASH, self.consume_char(), loc)
         elif c.isdigit():
             num, loc = self.consume_number()
             return Token(TokenType.NUMBER, num, loc)
@@ -313,10 +318,9 @@ def main():
 
     tokens: [Token] = []
     token = parser.next_token()
-    tokens.append(token)
     while token != None:
-        token = parser.next_token()
         tokens.append(token)
+        token = parser.next_token()
 
     for t in tokens:
         pprint.pp(str(t))
index 42e0ee90ddc1b5a7038b798bca745a940041ced8..80e60a7cefb547bdc1a795ec64ce835a7f417933 100644 (file)
@@ -1,2 +1 @@
 "Token (String, 'This is a long ass string', ./tests/02-string.momo:1:0)"
-'None'
index 5523e7f80e3a6f1ae22222d28621d3053a027fab..aecc6b6a76106a42e484ee94ebf32deae7c6d0e6 100644 (file)
@@ -1,3 +1,2 @@
 ("Token (String, 'This is a long ass string', "
  './tests/03-whitespaced-string.momo:3:0)')
-'None'
index 0436921f0257898090b7e69015fa7c8dc1b6a320..d6c98992347b5e4609cbde9f1f975e515b5d39c2 100644 (file)
@@ -1,2 +1 @@
 "Token (Ident, 'foo', ./tests/04-identifier.momo:1:4)"
-'None'
index 665fb2524d7deda949eeb90110d883cd4469d923..8dbb042df74a8014031ed8731b134e235d0b7ba0 100644 (file)
@@ -1,4 +1,3 @@
 "Token (Ident, 'foo', ./tests/05-multiple-identifiers.momo:1:3)"
 "Token (Ident, 'bar', ./tests/05-multiple-identifiers.momo:2:1)"
 "Token (Ident, 'baz', ./tests/05-multiple-identifiers.momo:2:5)"
-'None'
index 78b6e3c7a7eae4e70f79a928753fcd359b5a43c1..013b553ba459719920d324369c7f9c3cdf6b4a43 100644 (file)
@@ -22,4 +22,3 @@
 "Token (Colon, ':', ./tests/06-single-char-symbols.momo:5:2)"
 "Token (Semicolon, ';', ./tests/06-single-char-symbols.momo:5:4)"
 "Token (Dot, '.', ./tests/06-single-char-symbols.momo:5:6)"
-'None'
index 164c751cf60ee01a91f64159a7b4b7f4c55775a0..87abb27fedbf566fd739f35e6bf86cb531138f34 100644 (file)
@@ -1,3 +1,2 @@
 "Token (Number, '69', ./tests/07-numbers.momo:1:1)"
 "Token (Number, '100', ./tests/07-numbers.momo:3:1)"
-'None'
index a2544596a7f85fad1f290b5f5c5956b3399b1b30..70ba7c314554d623a3831a568deb59afeb2ecd38 100644 (file)
@@ -1,4 +1,3 @@
 "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'