lang: lex: add function to check if tokens are available

if this function returns false, any attempt to read tokens from the lexer will cause another line of input to be retrieved from the lexer's line source.
This commit is contained in:
2024-11-23 19:27:29 +00:00
parent 54a0c331b2
commit b630aa009c
2 changed files with 14 additions and 0 deletions

View File

@@ -124,6 +124,7 @@ IVY_API enum ivy_status ivy_lexer_get_status(struct ivy_lexer *lex);
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 void ivy_token_destroy(struct ivy_token *tok);

View File

@@ -1049,6 +1049,19 @@ struct ivy_token *ivy_lexer_read(struct ivy_lexer *lex)
return tok;
}
bool ivy_lexer_tokens_available(struct ivy_lexer *lex)
{
if (lex->lex_queue) {
return true;
}
if (input_available(lex)) {
return true;
}
return false;
}
void ivy_token_destroy(struct ivy_token *tok)
{
switch (tok->t_type) {