From b630aa009c8649a29eae4fed19e2e30d1dc784bb Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 23 Nov 2024 19:27:29 +0000 Subject: [PATCH] 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. --- lang/include/ivy/lang/lex.h | 1 + lang/lex.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lang/include/ivy/lang/lex.h b/lang/include/ivy/lang/lex.h index 52c5f8f..cf127c4 100644 --- a/lang/include/ivy/lang/lex.h +++ b/lang/include/ivy/lang/lex.h @@ -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); diff --git a/lang/lex.c b/lang/lex.c index 15ef983..fd9ddb3 100644 --- a/lang/lex.c +++ b/lang/lex.c @@ -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) {