summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Maniero <carlosmaniero@gmail.com>2023-04-14 13:01:29 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-04-14 18:09:13 +0200
commitbe27abdc5d7895d612237803277766621601662a (patch)
tree42ec3c5647e62cd0d1924dd1ec4b2a38033edbfe
parentf5731b3f56c7341da5f4a74cd1de57401ef427a5 (diff)
cli: Create a function to print tokens
This logic was inside the main function Signed-off-by: Carlos Maniero <carlosmaniero@gmail.com>
-rw-r--r--pipac.c13
1 files changed, 9 insertions, 4 deletions
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 <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;
}