Combine TK_TRUE and TK_FALSE into TK_BOOL
This commit is contained in:
parent
75b18d96ee
commit
740d9b6566
@ -16,8 +16,7 @@ typedef enum {
|
|||||||
TK_L_BRACKET,
|
TK_L_BRACKET,
|
||||||
TK_R_BRACKET,
|
TK_R_BRACKET,
|
||||||
TK_NULL,
|
TK_NULL,
|
||||||
TK_TRUE,
|
TK_BOOL,
|
||||||
TK_FALSE,
|
|
||||||
TK_STR_KEY,
|
TK_STR_KEY,
|
||||||
TK_STR_VAL,
|
TK_STR_VAL,
|
||||||
TK_INTEGER,
|
TK_INTEGER,
|
||||||
@ -29,6 +28,7 @@ typedef union {
|
|||||||
i64 num_int;
|
i64 num_int;
|
||||||
f64 num_frac;
|
f64 num_frac;
|
||||||
str_view_t string;
|
str_view_t string;
|
||||||
|
bool boolean;
|
||||||
} token_value_t;
|
} token_value_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -301,11 +301,9 @@ void print_token(token_t token) {
|
|||||||
case TK_NULL:
|
case TK_NULL:
|
||||||
printf("%15s, VALUE: N/A", "TK_NULL");
|
printf("%15s, VALUE: N/A", "TK_NULL");
|
||||||
break;
|
break;
|
||||||
case TK_TRUE:
|
case TK_BOOL:
|
||||||
printf("%15s, VALUE: N/A", "TK_TRUE");
|
printf("%15s, VALUE: %s", "TK_BOOL",
|
||||||
break;
|
token.value.boolean ? "true" : "false");
|
||||||
case TK_FALSE:
|
|
||||||
printf("%15s, VALUE: N/A", "TK_FALSE");
|
|
||||||
break;
|
break;
|
||||||
case TK_STR_KEY:
|
case TK_STR_KEY:
|
||||||
printf("%15s, VALUE: %s", "TK_STR_KEY", token.value.string);
|
printf("%15s, VALUE: %s", "TK_STR_KEY", token.value.string);
|
||||||
@ -1070,9 +1068,11 @@ lexer_state_t handle_keyword_end(lexer_t *lexer, char input) {
|
|||||||
if (strequal(keyword, "null")) {
|
if (strequal(keyword, "null")) {
|
||||||
set_token(token, lexer->line, column, TK_NULL, (token_value_t){0});
|
set_token(token, lexer->line, column, TK_NULL, (token_value_t){0});
|
||||||
} else if (strequal(keyword, "true")) {
|
} else if (strequal(keyword, "true")) {
|
||||||
set_token(token, lexer->line, column, TK_TRUE, (token_value_t){0});
|
set_token(token, lexer->line, column, TK_BOOL,
|
||||||
|
(token_value_t){.boolean = true});
|
||||||
} else if (strequal(keyword, "false")) {
|
} else if (strequal(keyword, "false")) {
|
||||||
set_token(token, lexer->line, column, TK_FALSE, (token_value_t){0});
|
set_token(token, lexer->line, column, TK_BOOL,
|
||||||
|
(token_value_t){.boolean = false});
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_lex_str(&(lexer->keyword));
|
clear_lex_str(&(lexer->keyword));
|
||||||
|
Loading…
Reference in New Issue
Block a user