Skip to content

Commit

Permalink
[cpp] implemented else-if
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 15, 2024
1 parent 7083144 commit e10d450
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion cpp/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,22 @@ namespace parse
if(maybe_else.has_value() && maybe_else->t == lex::type::keyword_else)
{
if(!retr.avail()){return false;}
// block OR another if statement (else-if)
ast::node blk2_node;
auto blk2 = retr.retrieve<ast::block>(nullptr, &blk2_node);
if(!blk2.has_value())
{
return false;
retr.undo();
ast::node nested_if_node;
auto nested_if = retr.retrieve<ast::if_statement>(nullptr, &nested_if_node);
if(!nested_if.has_value())
{
return false;
}
nested_if_node.payload = ast::expression{.expr = nested_if.value()};
blk2_node.payload = ast::block{};
blk2_node.meta = nested_if_node.meta;
blk2_node.children = {nested_if_node};
}
else_node = blk2_node;
}
Expand Down
13 changes: 12 additions & 1 deletion samples/scratchpad.psy
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ morb :: (par0 : i64) -> f64
{
e : i64 := 5;
}
else
else if poggers2 == 12
{
// ur cringe m8.
d : i64 := 5;
if par0 == 5
{

}
else
{
if poggers3 == 0
{

}
}
}

retval : f64;
Expand Down

0 comments on commit e10d450

Please sign in to comment.