about summary refs log tree commit diff
path: root/boot/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/lex.c')
-rw-r--r--boot/lex.c18
1 files changed, 18 insertions, 0 deletions
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)
 {