LibCpp: Add support for parsing function types

This makes it work with types like `Function<T(U, V)>`.
This commit is contained in:
Ali Mohammad Pur 2021-07-28 06:04:51 +04:30 committed by Andreas Kling
commit 5f66874ea0
Notes: sideshowbarker 2024-07-18 07:36:21 +09:00
3 changed files with 66 additions and 0 deletions

View file

@ -1255,7 +1255,19 @@ NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent)
type = ref;
}
if (peek().type() == Token::Type::LeftParen) {
consume();
auto fn_type = create_ast_node<FunctionType>(parent, type->start(), position());
fn_type->set_return_type(*type);
type->set_parent(*fn_type);
if (auto parameters = parse_parameter_list(*type); parameters.has_value())
fn_type->set_parameters(parameters.release_value());
consume(Token::Type::RightParen);
type = fn_type;
}
type->set_end(position());
return type;
}