diff options
| author | Mel <mel@rnrd.eu> | 2025-06-24 20:31:13 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-24 20:31:13 +0200 |
| commit | 3d983097329607cc89b63425e97527c5ec0390c8 (patch) | |
| tree | c1d50be52948ce26ac6134843093c0d4bec60f64 /boot/parse.c | |
| parent | 7b3117e92393f1d62991f55aa4ee8178e358689a (diff) | |
| download | catskill-3d983097329607cc89b63425e97527c5ec0390c8.tar.zst catskill-3d983097329607cc89b63425e97527c5ec0390c8.zip | |
Parse Maybe (?) type
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/parse.c')
| -rw-r--r-- | boot/parse.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/boot/parse.c b/boot/parse.c index ac324f9..976bc4b 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -546,9 +546,8 @@ parser_node_type_reference(struct Parser* p, struct Parser_Error* error) } struct Type_Node* -parser_node_type(struct Parser* p, struct Parser_Error* error) +parser_node_type_inner(struct Parser* p, struct Parser_Error* error) { - // TODO: maybe, variant, class struct Token token = parser_peek(p); switch (token.kind) { case TOKEN_NAME: @@ -573,6 +572,22 @@ parser_node_type(struct Parser* p, struct Parser_Error* error) } } +struct Type_Node* +parser_node_type(struct Parser* p, struct Parser_Error* error) +{ + struct Type_Node* type = CHECK(parser_node_type_inner(p, error)); + + // check if the type is followed by a `?`, which means it may be nil. + if (parser_probe(p, TOKEN_QUESTION)) { + parser_next(p); // consume the question mark + type = type_node_new( + TYPE_NODE_MAYBE, (union Type_Node_Value){ .maybe = { type } }, type->span, + type->location); + } + + return type; +} + struct Expression* parser_expression_primary_name(struct Parser* p, struct Parser_Error* error) { |
