From 8c33464656ef7dd874431e5770b1b4835e3022fe Mon Sep 17 00:00:00 2001 From: samsonium Date: Sat, 17 Oct 2026 21:23:50 +0300 Subject: [PATCH] feat: add `null` as value token --- include/compiler/fzl_token.h | 1 + src/compiler/fzl_parser.c | 15 ++++----------- src/compiler/fzl_reader.c | 5 ++++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/compiler/fzl_token.h b/include/compiler/fzl_token.h index 30b5f81..a051cd0 100644 --- a/include/compiler/fzl_token.h +++ b/include/compiler/fzl_token.h @@ -34,6 +34,7 @@ typedef enum FZL_TOKTYPE_STR_LITERAL, // "" FZL_TOKTYPE_NUM_LITERAL, // 123 FZL_TOKTYPE_BOOL_LITERAL, // true + FZL_TOKTYPE_NULL_LITERAL, // null FZL_TOKTYPE_DAMPERSAND, // && FZL_TOKTYPE_DVBAR, // || diff --git a/src/compiler/fzl_parser.c b/src/compiler/fzl_parser.c index 8c6f8ba..43154fc 100644 --- a/src/compiler/fzl_parser.c +++ b/src/compiler/fzl_parser.c @@ -140,17 +140,10 @@ fzl_node_t *parse_primary(fzl_parser_t *parser) if (!parser || !peek(parser)) return NULL; - if (is(parser, FZL_TOKTYPE_STR_LITERAL)) - { - fzl_token_t *tok = consume(parser); - return fzl_mknode(FZL_NODETYPE_LITERAL, tok); - } - else if (is(parser, FZL_TOKTYPE_NUM_LITERAL)) - { - fzl_token_t *tok = consume(parser); - return fzl_mknode(FZL_NODETYPE_LITERAL, tok); - } - else if (is(parser, FZL_TOKTYPE_BOOL_LITERAL)) + if (is(parser, FZL_TOKTYPE_STR_LITERAL) || + is(parser, FZL_TOKTYPE_NUM_LITERAL) || + is(parser, FZL_TOKTYPE_BOOL_LITERAL) || + is(parser, FZL_TOKTYPE_NULL_LITERAL)) { fzl_token_t *tok = consume(parser); return fzl_mknode(FZL_NODETYPE_LITERAL, tok); diff --git a/src/compiler/fzl_reader.c b/src/compiler/fzl_reader.c index bc4e3e5..683fb3f 100644 --- a/src/compiler/fzl_reader.c +++ b/src/compiler/fzl_reader.c @@ -88,13 +88,16 @@ fzl_token_t *parse_name(fzl_reader_t *reader) else if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) tok = fzl_mktoken(FZL_TOKTYPE_BOOL_LITERAL, l.line, l.col, value, size, l.filename); + else if (strcmp(value, "null") == 0) + tok = fzl_mktoken(FZL_TOKTYPE_NULL_LITERAL, l.line, l.col, value, size, + l.filename); else if (strcmp(value, "str") == 0 || strcmp(value, "char") == 0 || strcmp(value, "bool") == 0 || strcmp(value, "uint") == 0 || strcmp(value, "int") == 0 || strcmp(value, "i8") == 0 || strcmp(value, "i16") == 0 || strcmp(value, "i32") == 0 || strcmp(value, "i64") == 0 || strcmp(value, "u8") == 0 || strcmp(value, "u16") == 0 || strcmp(value, "u32") == 0 || - strcmp(value, "u64") == 0 || strcmp(value, "null") == 0) + strcmp(value, "u64") == 0) tok = fzl_mktoken(FZL_TOKTYPE_TYPE, l.line, l.col, value, size, l.filename); else tok = fzl_mktoken(FZL_TOKTYPE_NAME, l.line, l.col, value, size, l.filename);