diff options
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); } |
