about summary refs log tree commit diff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/lex.c10
-rw-r--r--boot/parse.c15
2 files changed, 24 insertions, 1 deletions
diff --git a/boot/lex.c b/boot/lex.c
index e8432f6..c850534 100644
--- a/boot/lex.c
+++ b/boot/lex.c
@@ -84,6 +84,8 @@ enum Token_Kind
     TOKEN_WORD_RETURN,
     TOKEN_WORD_VAR,
     TOKEN_WORD_TYPE,
+    TOKEN_WORD_TRUE,
+    TOKEN_WORD_FALSE,
 
     TOKEN_ROUND_OPEN,
     TOKEN_ROUND_CLOSE,
@@ -160,6 +162,10 @@ token_kind_to_string(enum Token_Kind kind)
         return "WORD_VAR";
     case TOKEN_WORD_TYPE:
         return "WORD_TYPE";
+    case TOKEN_WORD_TRUE:
+        return "WORD_TRUE";
+    case TOKEN_WORD_FALSE:
+        return "WORD_FALSE";
 
     case TOKEN_ROUND_OPEN:
         return "ROUND_OPEN";
@@ -612,6 +618,10 @@ lexer_word_from_name(struct Lexer* l, struct String word_or_name)
         return TOKEN_WORD_VAR;
     case 91700392: // "type"
         return TOKEN_WORD_TYPE;
+    case 2588936279: // "true"
+        return TOKEN_WORD_TRUE;
+    case 1548710142: // "false"
+        return TOKEN_WORD_FALSE;
     default:
         return TOKEN_NONE;
     }
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;