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:
@@ -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);
|
||||
|
||||
|
||||
13
lang/lex.c
13
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) {
|
||||
|
||||
Reference in New Issue
Block a user