diff options
author | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-14 13:01:29 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-14 18:09:13 +0200 |
commit | be27abdc5d7895d612237803277766621601662a (patch) | |
tree | 42ec3c5647e62cd0d1924dd1ec4b2a38033edbfe /pipac.c | |
parent | f5731b3f56c7341da5f4a74cd1de57401ef427a5 (diff) |
cli: Create a function to print tokens
This logic was inside the main function
Signed-off-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'pipac.c')
-rw-r--r-- | pipac.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -227,6 +227,14 @@ print_usage() fputs("pipac <filename.pipa>\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; } |