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.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/boot/lex.c b/boot/lex.c
index 2efb33d..594905f 100644
--- a/boot/lex.c
+++ b/boot/lex.c
@@ -192,6 +192,8 @@ enum Token_Kind
     TOKEN_ASSIGN_RIGHT_SHIFT,
 };
 
+// returns a string representation of the token kind.
+// non-human-friendly, for debugging purposes.
 const ascii*
 token_kind_to_string(enum Token_Kind kind)
 {
@@ -454,8 +456,9 @@ token_can_begin_declaration(const struct Token* t)
     return token_is(t, TOKEN_WORD_VAR) || token_is(t, TOKEN_WORD_LET);
 }
 
+// prints non-human-friendly representation of the token kind, along with its value, if applicable.
 void
-token_print(const struct Token* t)
+token_debug_print(const struct Token* t)
 {
     printf("%s", token_kind_to_string(t->kind));
 
@@ -472,6 +475,13 @@ token_print(const struct Token* t)
     }
 }
 
+// get a view of the token's lexeme in the source file.
+struct String_View
+token_lexeme(const struct Token* t, struct String source)
+{
+    return string_substring(source, t->span.start, t->span.end);
+}
+
 bool
 ascii_in_range(ascii c, ascii from, ascii to)
 {