From 3620cabd1d722e4acc761c7278aa44aba902006c Mon Sep 17 00:00:00 2001 From: Mel Date: Sun, 6 Jul 2025 15:25:47 +0200 Subject: Print formatted lex token value next to token type Signed-off-by: Mel --- boot/lex.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'boot/lex.c') diff --git a/boot/lex.c b/boot/lex.c index 82d3567..c705f26 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -429,6 +429,24 @@ token_can_begin_declaration(const struct Token* t) return token_is(t, TOKEN_WORD_VAR) || token_is(t, TOKEN_WORD_LET); } +void +token_print(const struct Token* t) +{ + printf("%s", token_kind_to_string(t->kind)); + + if (token_is(t, TOKEN_NAME)) { + printf("(%s)", t->value.name.data); + } else if (token_is(t, TOKEN_LITERAL_INTEGER)) { + printf("(%ld)", t->value.literal_integer); + } else if (token_is(t, TOKEN_LITERAL_FLOAT)) { + printf("(%f)", t->value.literal_float); + } else if (token_is(t, TOKEN_LITERAL_STRING)) { + printf("(%s)", t->value.name.data); + } else if (token_is(t, TOKEN_SOMETHING)) { + printf("(%c)", t->value.unknown_character); + } +} + bool ascii_in_range(ascii c, ascii from, ascii to) { -- cgit 1.4.1