From: Alexander Goussas Date: Thu, 31 Oct 2024 02:25:35 +0000 (-0500) Subject: feat: lex barewords X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=151d0bb5386634ee5b60261157de5c93b15aaf68;p=so-test.git feat: lex barewords --- 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}; }