list<list<name>> collect_choice_symbols(expr const & e) { buffer<list<name>> r; for_each(e, [&](expr const & e, unsigned) { if (is_choice(e)) { buffer<name> cs; for (unsigned i = 0; i < get_num_choices(e); i++) { expr const & c = get_app_fn(get_choice(e, i)); if (is_constant(c)) cs.push_back(const_name(c)); else if (is_local(c)) cs.push_back(mlocal_pp_name(c)); } if (cs.size() > 1) r.push_back(to_list(cs)); } return true; }); return to_list(r); }
expr const & get_choice(expr const & e, unsigned i) { lean_assert(is_choice(e)); return macro_arg(e, i); }
static void check_choice(lua_State * L, int idx) { if (!is_choice(to_expr(L, idx))) throw exception(sstream() << "arg #" << idx << " is not a choice-expression"); }
unsigned get_num_choices(expr const & e) { lean_assert(is_choice(e)); return macro_num_args(e); }
static int is_choice(lua_State * L) { return push_boolean(L, is_choice(to_expr(L, 1))); }