Updated print_token function
This commit is contained in:
parent
2a4d573118
commit
7e4d82888a
@ -280,42 +280,51 @@ bool validate_json(char *json) {
|
||||
}
|
||||
|
||||
void print_token(token_t token) {
|
||||
printf("{LINE: %4llu, COLUMN: %4llu, TYPE: ", (unsigned long long)token.line,
|
||||
i32 num_padding = 4;
|
||||
|
||||
printf("{LINE: %*llu, COLUMN: %*llu, TYPE: ", num_padding,
|
||||
(unsigned long long)token.line, num_padding,
|
||||
(unsigned long long)token.column);
|
||||
|
||||
i32 token_type_padding = 15;
|
||||
|
||||
switch (token.type) {
|
||||
case TK_NO_TOKEN:
|
||||
break;
|
||||
case TK_L_BRACE:
|
||||
printf("%15s, VALUE: N/A", "TK_L_BRACE");
|
||||
printf("%*s, VALUE: N/A", token_type_padding, "TK_L_BRACE");
|
||||
break;
|
||||
case TK_R_BRACE:
|
||||
printf("%15s, VALUE: N/A", "TK_R_BRACE");
|
||||
printf("%*s, VALUE: N/A", token_type_padding, "TK_R_BRACE");
|
||||
break;
|
||||
case TK_L_BRACKET:
|
||||
printf("%15s, VALUE: N/A", "TK_L_BRACKET");
|
||||
printf("%*s, VALUE: N/A", token_type_padding, "TK_L_BRACKET");
|
||||
break;
|
||||
case TK_R_BRACKET:
|
||||
printf("%15s, VALUE: N/A", "TK_R_BRACKET");
|
||||
printf("%*s, VALUE: N/A", token_type_padding, "TK_R_BRACKET");
|
||||
break;
|
||||
case TK_NULL:
|
||||
printf("%15s, VALUE: N/A", "TK_NULL");
|
||||
printf("%*s, VALUE: N/A", token_type_padding, "TK_NULL");
|
||||
break;
|
||||
case TK_BOOL:
|
||||
printf("%15s, VALUE: %s", "TK_BOOL",
|
||||
printf("%*s, VALUE: %s", token_type_padding, "TK_BOOL",
|
||||
token.value.boolean ? "true" : "false");
|
||||
break;
|
||||
case TK_STR_KEY:
|
||||
printf("%15s, VALUE: %s", "TK_STR_KEY", token.value.string);
|
||||
printf("%*s, VALUE: %s", token_type_padding, "TK_STR_KEY",
|
||||
token.value.string);
|
||||
break;
|
||||
case TK_STR_VAL:
|
||||
printf("%15s, VALUE: %s", "TK_STR_VAL", token.value.string);
|
||||
printf("%*s, VALUE: %s", token_type_padding, "TK_STR_VAL",
|
||||
token.value.string);
|
||||
break;
|
||||
case TK_INTEGER:
|
||||
printf("%15s, VALUE: %lld", "TK_INTEGER", (long long)token.value.num_int);
|
||||
printf("%*s, VALUE: %lld", token_type_padding, "TK_INTEGER",
|
||||
(long long)token.value.num_int);
|
||||
break;
|
||||
case TK_DOUBLE:
|
||||
printf("%15s, VALUE: %f", "TK_DOUBLE", token.value.num_frac);
|
||||
printf("%*s, VALUE: %f", token_type_padding, "TK_DOUBLE",
|
||||
token.value.num_frac);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user