From 151d0bb5386634ee5b60261157de5c93b15aaf68 Mon Sep 17 00:00:00 2001 From: Alexander Goussas Date: Wed, 30 Oct 2024 21:25:35 -0500 Subject: [PATCH] feat: lex barewords --- lexer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lexer.c b/lexer.c index a0c3bef..29dd618 100644 --- a/lexer.c +++ b/lexer.c @@ -2,6 +2,7 @@ #include #include #include +#include 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}; } -- 2.43.0