diff --git a/lang/include/ivy/lang/lex.h b/lang/include/ivy/lang/lex.h index f06ec37..ec0e339 100644 --- a/lang/include/ivy/lang/lex.h +++ b/lang/include/ivy/lang/lex.h @@ -137,6 +137,9 @@ IVY_API struct ivy_token *ivy_lexer_peek(struct ivy_lexer *lex); IVY_API struct ivy_token *ivy_lexer_read(struct ivy_lexer *lex); IVY_API bool ivy_lexer_tokens_available(struct ivy_lexer *lex); +IVY_API struct ivy_token *ivy_token_create_ident(const char *s); +IVY_API void ivy_token_destroy(struct ivy_token *tok); + static inline bool ivy_token_is_symbol(struct ivy_token *tok, enum ivy_symbol sym) { return (tok->t_type == IVY_TOK_SYMBOL && tok->t_symbol == sym); @@ -145,7 +148,6 @@ static inline bool ivy_token_is_keyword(struct ivy_token *tok, enum ivy_keyword { return (tok->t_type == IVY_TOK_KEYWORD && tok->t_keyword == kw); } -IVY_API void ivy_token_destroy(struct ivy_token *tok); IVY_API const char *ivy_lex_token_type_to_string(enum ivy_token_type type); IVY_API const char *ivy_keyword_to_string(enum ivy_keyword keyword); diff --git a/lang/lex.c b/lang/lex.c index 1649491..dc94217 100644 --- a/lang/lex.c +++ b/lang/lex.c @@ -1066,6 +1066,27 @@ bool ivy_lexer_tokens_available(struct ivy_lexer *lex) return false; } +struct ivy_token *ivy_token_create_ident(const char *s) +{ + struct ivy_token *tok = malloc(sizeof *tok); + + if (!tok) { + return NULL; + } + + memset(tok, 0x0, sizeof *tok); + + tok->t_type = IVY_TOK_IDENT; + tok->t_str = b_strdup(s); + + if (!tok->t_str) { + free(tok); + return NULL; + } + + return tok; +} + void ivy_token_destroy(struct ivy_token *tok) { switch (tok->t_type) {