From 412e9abf057f6958bd898c2e8fd0862f0f2937f4 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 16 Nov 2024 23:03:16 +0000 Subject: [PATCH] frontend: compile: add colour-coding to token list --- frontend/cmd/compile.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/frontend/cmd/compile.c b/frontend/cmd/compile.c index fcdf5fe..7061b78 100644 --- a/frontend/cmd/compile.c +++ b/frontend/cmd/compile.c @@ -44,11 +44,47 @@ static int compile_file(const char *path) break; } + switch (tok->t_type) { + case IVY_TOK_KEYWORD: + b_fputs("[magenta]", stdout); + break; + case IVY_TOK_SYMBOL: + b_fputs("[blue]", stdout); + break; + case IVY_TOK_ATOM: + b_fputs("[yellow]", stdout); + break; + case IVY_TOK_NUMBER: + b_fputs("[yellow]", stdout); + break; + case IVY_TOK_LABEL: + b_fputs("[red]", stdout); + break; + case IVY_TOK_IDENT: + b_fputs("[cyan]", stdout); + break; + case IVY_TOK_STRING: + b_fputs("[green]", stdout); + break; + case IVY_TOK_STR_START: + b_fputs("[green]", stdout); + break; + case IVY_TOK_STR_END: + b_fputs("[green]", stdout); + break; + case IVY_TOK_LINEFEED: + b_fputs("[bright,black]", stdout); + break; + default: + break; + } + printf("%s", ivy_lex_token_type_to_string(tok->t_type)); switch (tok->t_type) { case IVY_TOK_IDENT: case IVY_TOK_LABEL: + case IVY_TOK_STRING: printf("(%s)", tok->t_str); break; case IVY_TOK_SYMBOL: @@ -61,7 +97,7 @@ static int compile_file(const char *path) break; } - printf("\n"); + b_fputs("[reset]\n", stdout); } int r = (lex.lex_status == IVY_OK || lex.lex_status == IVY_ERR_EOF) ? 0