From be27abdc5d7895d612237803277766621601662a Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Fri, 14 Apr 2023 13:01:29 -0300 Subject: cli: Create a function to print tokens This logic was inside the main function Signed-off-by: Carlos Maniero --- pipac.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'pipac.c') diff --git a/pipac.c b/pipac.c index a93e77f..dba6109 100644 --- a/pipac.c +++ b/pipac.c @@ -227,6 +227,14 @@ print_usage() fputs("pipac \n", stderr); } +void +print_tokens(lexer_t *lexer) { + token_t token; + for (lexer_next_token(lexer, &token); token.kind != TOKEN_EOF; lexer_next_token(lexer, &token)) { + printf("%s:%d:%d: [kind=%d, value='%s']\n", lexer->filepath, token.row + 1, token.col + 1, token.kind, token.value); + } +} + int main(int argc, char **argv) { @@ -242,10 +250,7 @@ main(int argc, char **argv) printf("[INFO]: %ld bytes loaded [filename='%s']\n", lexer.srclen, lexer.filepath); - token_t token; - for (lexer_next_token(&lexer, &token); token.kind != TOKEN_EOF; lexer_next_token(&lexer, &token)) { - printf("%s:%d:%d: [kind=%d, value='%s']\n", lexer.filepath, token.row + 1, token.col + 1, token.kind, token.value); - } + print_tokens(&lexer); return EXIT_SUCCESS; } -- cgit v1.2.3