lang: lex: add function for creating fake ident tokens
This commit is contained in:
@@ -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 struct ivy_token *ivy_lexer_read(struct ivy_lexer *lex);
|
||||||
IVY_API bool ivy_lexer_tokens_available(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)
|
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);
|
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);
|
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_lex_token_type_to_string(enum ivy_token_type type);
|
||||||
IVY_API const char *ivy_keyword_to_string(enum ivy_keyword keyword);
|
IVY_API const char *ivy_keyword_to_string(enum ivy_keyword keyword);
|
||||||
|
|||||||
21
lang/lex.c
21
lang/lex.c
@@ -1066,6 +1066,27 @@ bool ivy_lexer_tokens_available(struct ivy_lexer *lex)
|
|||||||
return false;
|
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)
|
void ivy_token_destroy(struct ivy_token *tok)
|
||||||
{
|
{
|
||||||
switch (tok->t_type) {
|
switch (tok->t_type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user