Parse initialization statement
This commit is contained in:
parent
7aaa665058
commit
db60335507
@ -50,6 +50,23 @@ namespace parsing {
|
||||
auto ret = new AST::ReturnStatement{ std::move(expression) };
|
||||
return new std::unique_ptr<AST::Statement>{ ret };
|
||||
}
|
||||
else if (inner.peek().type == token::Type::Ident) {
|
||||
auto ty = parse_type(inner).unwrap();
|
||||
auto name = inner.expect(token::Type::Ident);
|
||||
|
||||
std::optional<std::unique_ptr<AST::Expression>> expr = {};
|
||||
if (inner.peek().type == token::Type::Symbol && inner.peek().content == "=") {
|
||||
std::cout << "hello" << std::endl;
|
||||
inner.expect(token::Type::Symbol, "=");
|
||||
expr = parse_expression(inner).unwrap();
|
||||
}
|
||||
|
||||
inner.expect(token::Type::Symbol, ";");
|
||||
|
||||
stream.m_position = inner.m_position;
|
||||
auto init = new AST::InitializationStatement{ std::move(ty), name.content, std::move(expr) };
|
||||
return new std::unique_ptr<AST::Statement>{ init };
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Expected return-keyword");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user