diff options
| -rw-r--r-- | boot/catboot.c | 3 | ||||
| -rw-r--r-- | boot/lex.c | 18 | ||||
| -rw-r--r-- | boot/tests/lex/basic.cskt | 2 |
3 files changed, 21 insertions, 2 deletions
diff --git a/boot/catboot.c b/boot/catboot.c index e2e5315..53b2bed 100644 --- a/boot/catboot.c +++ b/boot/catboot.c @@ -87,7 +87,8 @@ debug_lex_pass(struct String source) struct Token token; do { token = lexer_next(&lexer); - printf("%s ", token_kind_to_string(token.kind)); + token_print(&token); + printf(" "); } while (token.kind != TOKEN_END_OF_FILE); return 0; 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) { diff --git a/boot/tests/lex/basic.cskt b/boot/tests/lex/basic.cskt index 7380498..26b41f3 100644 --- a/boot/tests/lex/basic.cskt +++ b/boot/tests/lex/basic.cskt @@ -9,4 +9,4 @@ main = fun () int { >>> -NAME ASSIGN WORD_FUN ROUND_OPEN ROUND_CLOSE NAME CURLY_OPEN NEWLINE WORD_RETURN LITERAL_INTEGER PLUS LITERAL_INTEGER NEWLINE CURLY_CLOSE END_OF_FILE +NAME(main) ASSIGN WORD_FUN ROUND_OPEN ROUND_CLOSE NAME(int) CURLY_OPEN NEWLINE WORD_RETURN LITERAL_INTEGER(1) PLUS LITERAL_INTEGER(2) NEWLINE CURLY_CLOSE END_OF_FILE |
