about summary refs log tree commit diff
path: root/boot/parse.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-05-23 18:29:17 +0200
committerMel <mel@rnrd.eu>2025-05-23 18:29:17 +0200
commit262592dfd2dcf74f4349cf0b58969f7b977a195c (patch)
treef7e089f0e5f5a8525bd835386a6dc470dd1e9d28 /boot/parse.c
parent1e07cecafc62d18ba05f21101e13b131a10e8c45 (diff)
downloadcatskill-262592dfd2dcf74f4349cf0b58969f7b977a195c.tar.zst
catskill-262592dfd2dcf74f4349cf0b58969f7b977a195c.zip
Lex boolean literals
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/parse.c')
-rw-r--r--boot/parse.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/boot/parse.c b/boot/parse.c
index 38cb712..b009656 100644
--- a/boot/parse.c
+++ b/boot/parse.c
@@ -194,6 +194,17 @@ parser_expression_primary_string(struct Parser* p, struct Parser_Error* error)
 }
 
 struct Expression*
+parser_expression_primary_boolean(struct Parser* p, struct Parser_Error* error)
+{
+    struct Token token = parser_next(p);
+    check(token.kind == TOKEN_WORD_TRUE || token.kind == TOKEN_WORD_FALSE,
+          "expected boolean literal");
+    bool literal = token.kind == TOKEN_WORD_TRUE;
+    union Expression_Value expr_value = { .bool_literal = { literal } };
+    return expression_new(EXPRESSION_BOOLEAN_LITERAL, expr_value, token.span, token.location);
+}
+
+struct Expression*
 parser_expression_primary_group(struct Parser* p, struct Parser_Error* error)
 {
     struct Token start_token = CHECK(parser_need(p, TOKEN_ROUND_OPEN, error));
@@ -218,9 +229,11 @@ parser_expression_primary(struct Parser* p, struct Parser_Error* error)
         return parser_expression_primary_float(p, error);
     case TOKEN_LITERAL_STRING:
         return parser_expression_primary_string(p, error);
+    case TOKEN_WORD_TRUE:
+    case TOKEN_WORD_FALSE:
+        return parser_expression_primary_boolean(p, error);
     case TOKEN_ROUND_OPEN:
         return parser_expression_primary_group(p, error);
-    // TODO: boolean literals.
     default:
         *error = parser_error(PARSER_ERROR_EXPECTED_PRIMARY_EXPRESSION);
         return nil;