Skip to content

Commit

Permalink
libnixf: dispatch lambda formals correctly (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 26, 2024
1 parent 6eb1a24 commit e4651bb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions libnixf/src/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ std::shared_ptr<Expr> Parser::parseExpr() {
}
break;
}
case tok_r_curly:
switch (peek(2).kind()) {
case tok_at: // { } @
case tok_colon: // { } :
return parseExprLambda();
default:
break;
}
break;
case tok_ellipsis: // { ...
return parseExprLambda();
default:
Expand Down
2 changes: 1 addition & 1 deletion libnixf/test/Bytecode/Write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TEST_F(WriteTest, Complex) {
std::string Str = OS.str();
std::string_view Data(Str);

ASSERT_EQ(Str.size(), 2238);
ASSERT_EQ(Str.size(), 3334);

auto Kind = bc::eat<nixbc::ExprKind>(Data);

Expand Down
26 changes: 26 additions & 0 deletions libnixf/test/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@ TEST(Parser, ExprDispatch_r_curly_ellipsis) {
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, ExprDispatch_r_curly_l_curly_colon) {
// { ...
auto Src = R"({ } : 1)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);
ASSERT_EQ(AST->kind(), Node::NK_ExprLambda);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, ExprDispatch_r_curly_l_curly_at) {
// { ...
auto Src = R"({ } @ a: 1)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);
ASSERT_EQ(AST->kind(), Node::NK_ExprLambda);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, ExprIf) {
// if ... then ... else ...
auto Src = R"(if 1 then cc else "d")"sv;
Expand Down

0 comments on commit e4651bb

Please sign in to comment.