Exemplo n.º 1
0
int options_update(lua_State * L) {
    name k = to_name_ext(L, 2);
    auto it = get_option_declarations().find(k);
    if (it == get_option_declarations().end()) {
        throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'");
    } else {
        option_declaration const & d = it->second;
        switch (d.kind()) {
        case BoolOption:      return options_update_bool(L);
        case IntOption:       return options_update_int(L);
        case UnsignedOption:  return options_update_unsigned(L);
        case DoubleOption:    return options_update_double(L);
        case StringOption:    return options_update_string(L);
        default:              throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'");
        }
    }
}
Exemplo n.º 2
0
/**
   \brief Return a new set of options based on \c opts by adding the prefix \c prefix.

   The procedure throws an exception if \c opts contains an options (o, v), s.t. prefix + o is
   an unknown option in Lean.
*/
options add_prefix(name const & prefix, options const & opts) {
    option_declarations const & decls = get_option_declarations();
    return map(opts.m_value, [&](sexpr const & p) {
            name n = prefix + to_name(car(p));
            if (decls.find(n) == decls.end())
                throw exception(sstream() << "unknown option '" << n << "'");
            return cons(sexpr(n), cdr(p));
        });
}
Exemplo n.º 3
0
environment set_option_cmd(parser & p) {
    auto id_pos = p.pos();
    name id = p.check_id_next("invalid set option, identifier (i.e., option name) expected");
    auto decl_it = get_option_declarations().find(id);
    if (decl_it == get_option_declarations().end()) {
        // add "lean" prefix
        name lean_id = name("lean") + id;
        decl_it = get_option_declarations().find(lean_id);
        if (decl_it == get_option_declarations().end()) {
            throw parser_error(sstream() << "unknown option '" << id << "', type 'help options.' for list of available options", id_pos);
        } else {
            id = lean_id;
        }
    }
    option_kind k = decl_it->second.kind();
    if (k == BoolOption) {
        if (p.curr_is_token_or_id(g_true))
            p.set_option(id, true);
        else if (p.curr_is_token_or_id(g_false))
            p.set_option(id, false);
        else
            throw parser_error("invalid Boolean option value, 'true' or 'false' expected", p.pos());
        p.next();
    } else if (k == StringOption) {
        if (!p.curr_is_string())
            throw parser_error("invalid option value, given option is not a string", p.pos());
        p.set_option(id, p.get_str_val());
        p.next();
    } else if (k == DoubleOption) {
        p.set_option(id, p.parse_double());
    } else if (k == UnsignedOption || k == IntOption) {
        p.set_option(id, p.parse_small_nat());
    } else {
        throw parser_error("invalid option value, 'true', 'false', string, integer or decimal value expected", p.pos());
    }
    p.updt_options();
    return p.env();
}
Exemplo n.º 4
0
int mk_options(name const & prefix, lua_State * L) {
    options r;
    int nargs = lua_gettop(L);
    if (nargs % 2 != 0)
        throw exception("options expects an even number of arguments");
    for (int i = 1; i < nargs; i+=2) {
        name k = prefix + to_name_ext(L, i);
        auto it = get_option_declarations().find(k);
        if (it == get_option_declarations().end()) {
            throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'");
        } else {
            option_declaration const & d = it->second;
            switch (d.kind()) {
            case BoolOption:      r = r.update(k, static_cast<bool>(lua_toboolean(L, i+1))); break;
            case IntOption:       r = r.update(k, static_cast<int>(lua_tointeger(L, i+1))); break;
            case UnsignedOption:  r = r.update(k, static_cast<unsigned>(lua_tointeger(L, i+1))); break;
            case DoubleOption:    r = r.update(k, static_cast<double>(lua_tonumber(L, i+1))); break;
            case StringOption:    r = r.update(k, lua_tostring(L, i+1)); break;
            default:              throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'");
            }
        }
    }
    return push_options(L, r);
}