diff options
| author | Mel <mel@rnrd.eu> | 2025-06-15 03:50:48 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-15 03:50:48 +0200 |
| commit | 7ad3f400dde57f06ef52c2a9cf788a18d1891b7d (patch) | |
| tree | 40adba79cbb715647b1823a5e808c0edd407f5a3 /boot/parse.c | |
| parent | 59fa9cedffa29420f6a51895b672ba66d112c149 (diff) | |
| download | catskill-7ad3f400dde57f06ef52c2a9cf788a18d1891b7d.tar.zst catskill-7ad3f400dde57f06ef52c2a9cf788a18d1891b7d.zip | |
Remove confusion between function body and function with inline struct as return type
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/parse.c')
| -rw-r--r-- | boot/parse.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/boot/parse.c b/boot/parse.c index c06c5d3..9aeaf94 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -267,7 +267,16 @@ parser_function_header_node(struct Parser* p, struct Parser_Error* error) header.span = span_merge(open_parameters_token.span, close_parameters_token.span); struct Token next = parser_peek(p); - if (token_can_begin_type(&next)) { + struct Token further = parser_peek_further(p); + // NOTE: this is very uncomfortable. to avoid ambiguity between a no-return-type function body + // (i.e. `fun () {`) and a function with a return type of inline + // structure (i.e. `fun () {x int} {`), we require that inline structs are declared in one line, + // without a line-break, and function bodies always have a line-break after the opening brace. + // this means that we cannot have a single line function, and we can't have a function with an + // inline structure as a return type that is too long to fit on a single line. + // TODO: to allow single line functions, introduce a `:` token as a replacement for the + // opening brace. `fun (x int): x + 1` + if (token_can_begin_type(&next) && !token_is(&further, TOKEN_NEWLINE)) { header.return_type = CHECK_RETURN(parser_node_type(p, error), struct Function_Header_Node); header.span = span_merge(header.span, header.return_type->span); } |
