]> git.frustrated-labs.net Git - so-test.git/commitdiff
feat: lex barewords
authorAlexander Goussas <[email protected]>
Thu, 31 Oct 2024 02:25:35 +0000 (21:25 -0500)
committerAlexander Goussas <[email protected]>
Thu, 31 Oct 2024 02:25:35 +0000 (21:25 -0500)
lexer.c

diff --git a/lexer.c b/lexer.c
index a0c3befc47fa225fe1a04c08106a53a855839f99..29dd618aead2fc8684c8c885ae3639d33bc7cc98 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <ctype.h>
 
 static so_token so_lexer_string(so_lexer *);
 static so_token so_lexer_integer(so_lexer *);
@@ -114,4 +115,19 @@ so_token so_lexer_integer(so_lexer *l)
 
 so_token so_lexer_bareword(so_lexer *l)
 {
+    while (!so_lexer_eof(l) && !isspace(so_lexer_peek(l)))
+        so_lexer_advance(l);
+
+    char *lexeme = strndup(
+        &l->source[l->start],
+        l->current - l->start);
+
+    so_token_type type = SO_TT_BARE;
+
+    if (strcmp(lexeme, "use") == 0)
+        type = SO_TT_USE;
+    if (strcmp(lexeme, "call") == 0)
+        type = SO_TT_CALL;
+
+    return (so_token){.lexeme = lexeme, .type = type};
 }