static expr parse_struct_expr_core(parser & p, pos_info const & pos, bool curly_bar) { expr t = p.parse_expr(); buffer<name> field_names; buffer<expr> field_values; buffer<expr> using_exprs; while (p.curr_is_token(get_comma_tk())) { p.next(); pair<optional<name>, expr> id_e = p.parse_optional_assignment(); if (id_e.first) { field_names.push_back(*id_e.first); field_values.push_back(id_e.second); } else { using_exprs.push_back(id_e.second); } } if (curly_bar) p.check_token_next(get_rcurlybar_tk(), "invalid structure expression, '|}' expected"); else p.check_token_next(get_rdcurly_tk(), "invalid structure expression, '⦄' expected"); buffer<expr> args; args.push_back(t); args.append(field_values); args.append(using_exprs); return p.save_pos(mk_structure_instance(to_list(field_names), args.size(), args.data()), pos); }
expr parse_nested_declaration(parser & p, unsigned, expr const *, pos_info const & pos) { try { optional<name> n; decl_attributes attrs; if (!g_allow_nested_declarations) throw parser_error("invalid 'abstract' expression, it is only allowed inside definitions", pos); if (p.curr_is_token(get_as_tk())) { p.next(); n = p.check_id_next("invalid 'abstract' expression, identifier expected"); } attrs.parse(p); expr e = p.parse_expr(); p.check_token_next(get_end_tk(), "invalid 'abstract' expression, 'end' expected"); return p.save_pos(mk_nested_declaration(n, attrs, e), pos); } catch (exception & ex) { consume_until_end(p); ex.rethrow(); lean_unreachable(); } }