Skip to content

Commit c322ec3

Browse files
committed
Add parsing and cppfront emit lambdas in alternatives
1 parent 64f7198 commit c322ec3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

source/cppfront.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,10 +1273,16 @@ class cppfront
12731273
auto id = std::string{};
12741274
printer.emit_to_string(&id);
12751275
assert(alt->id_expression || alt->literal);
1276-
if (alt->id_expression)
1276+
if (alt->id_expression) {
12771277
emit(*alt->id_expression);
1278-
else if (alt->literal)
1278+
if (alt->expr) {
1279+
push_need_expression_list_parens(true);
1280+
emit(*alt->expr);
1281+
pop_need_expression_list_parens();
1282+
}
1283+
} else if (alt->literal) {
12791284
emit(*alt->literal);
1285+
}
12801286
printer.emit_to_string();
12811287

12821288
assert (*alt->is_as_keyword == "is" || *alt->is_as_keyword == "as");

source/parse.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ struct alternative_node
647647
source_position equal_sign;
648648
std::unique_ptr<statement_node> statement;
649649
token const* literal;
650+
std::unique_ptr<expression_list_node> expr;
650651

651652
auto position() const -> source_position
652653
{
@@ -2313,6 +2314,25 @@ class parser
23132314
return {};
23142315
}
23152316

2317+
if (curr().type() == lexeme::LeftParen) {
2318+
auto open_paren = curr().position();
2319+
next();
2320+
auto expr_list = expression_list(open_paren);
2321+
if (!expr_list) {
2322+
error("unexpected text - ( is not followed by an expression-list");
2323+
next();
2324+
return {};
2325+
}
2326+
if (curr().type() != lexeme::RightParen) {
2327+
error("unexpected text - expression-list is not terminated by )");
2328+
next();
2329+
return {};
2330+
}
2331+
expr_list->close_paren = curr().position();
2332+
next();
2333+
n->expr = std::move(expr_list);
2334+
}
2335+
23162336
if (curr().type() != lexeme::Assignment) {
23172337
error("expected = at start of inspect alternative body");
23182338
return {};

0 commit comments

Comments
 (0)