Skip to content

Commit feff7ec

Browse files
committed
Improve data output in print_token and print keyword data
1 parent bec465a commit feff7ec

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

parse.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,18 @@ static void print_token(struct Token *token) {
140140
fputs("Type: ", stdout);
141141
puts(token_type);
142142
fputs("Data: ", stdout);
143-
for (size_t c = 0; c < token->data_len; c++) putchar(token->data[c]);
143+
size_t i = 0;
144+
switch (token->type) {
145+
case TOK_WORD:
146+
if (!token->info) goto print_raw_data;
147+
fputs("<Keyword>", stdout);
148+
while (KEYWORD_MAP[i].symbol != *(enum Keyword *)token->info) ++i;
149+
fputs(KEYWORD_MAP[i].string, stdout);
150+
break;
151+
default:
152+
print_raw_data:
153+
for (size_t c = 0; c < token->data_len; c++) putchar(token->data[c]);
154+
}
144155
putchar('\n');
145156
}
146157

0 commit comments

Comments
 (0)