Add parsing of compound statements
This commit is contained in:
parent
a90259eccc
commit
28c733a5c8
@ -523,6 +523,23 @@ namespace parsing {
|
|||||||
token::TokenStream inner{ stream };
|
token::TokenStream inner{ stream };
|
||||||
auto before_meta = inner.metadata();
|
auto before_meta = inner.metadata();
|
||||||
try {
|
try {
|
||||||
|
if (inner.peek().type == token::Type::Symbol && inner.peek().content == "{") {
|
||||||
|
inner.expect(token::Type::Symbol, "{");
|
||||||
|
std::vector<std::unique_ptr<AST::Statement>> statements{};
|
||||||
|
Scope inner_scope{ scope };
|
||||||
|
while (inner.peek().content != "}") {
|
||||||
|
auto res = parse_statement(inner, inner_scope).unwrap();
|
||||||
|
if (res.second)
|
||||||
|
inner.expect(token::Type::Symbol, ";");
|
||||||
|
statements.push_back(std::move(res.first));
|
||||||
|
}
|
||||||
|
inner.expect(token::Type::Symbol, "}");
|
||||||
|
auto ret = new AST::CompoundStatement{ before_meta + stream.metadata(),std::move(statements) };
|
||||||
|
|
||||||
|
stream.m_position = inner.m_position;
|
||||||
|
|
||||||
|
return std::pair{ std::unique_ptr<AST::Statement>{ret}, false };
|
||||||
|
}
|
||||||
if (inner.peek().type == token::Type::ReturnKeyword) {
|
if (inner.peek().type == token::Type::ReturnKeyword) {
|
||||||
inner.next();
|
inner.next();
|
||||||
auto expression = parse_expression(inner, scope).unwrap();
|
auto expression = parse_expression(inner, scope).unwrap();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user