Add functions to skip over trivia in a tokenlist
This commit is contained in:
parent
ea5df2d129
commit
69e1cb840c
@ -81,3 +81,26 @@ error_t *tokenlist_fill(tokenlist_t *list, lexer_t *lex) {
|
||||
return err;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool is_trivia(tokenlist_entry_t *trivia) {
|
||||
switch (trivia->token.id) {
|
||||
case TOKEN_WHITESPACE:
|
||||
case TOKEN_COMMENT:
|
||||
case TOKEN_NEWLINE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
tokenlist_entry_t *tokenlist_skip_trivia(tokenlist_entry_t *current) {
|
||||
while (current && is_trivia(current))
|
||||
current = current->next;
|
||||
return current;
|
||||
}
|
||||
|
||||
tokenlist_entry_t *tokenlist_next(tokenlist_entry_t *current) {
|
||||
if (!current)
|
||||
return nullptr;
|
||||
return tokenlist_skip_trivia(current->next);
|
||||
}
|
||||
|
@ -27,4 +27,14 @@ error_t *tokenlist_fill(tokenlist_t *list, lexer_t *lex);
|
||||
|
||||
void tokenlist_free(tokenlist_t *list);
|
||||
|
||||
/**
|
||||
* Return the first token entry that isn't whitespace, newline or comment
|
||||
*/
|
||||
tokenlist_entry_t *tokenlist_skip_trivia(tokenlist_entry_t *current);
|
||||
|
||||
/**
|
||||
* Return the next token entry that isn't whitespace, newline or comment
|
||||
*/
|
||||
tokenlist_entry_t *tokenlist_next(tokenlist_entry_t *current);
|
||||
|
||||
#endif // INCLUDE_SRC_TOKENLIST_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user