feat(library/explicit): support partial explicit
This commit is contained in:
parent
1d670e3193
commit
946e00f71a
2 changed files with 39 additions and 2 deletions
|
@ -11,6 +11,7 @@ Author: Leonardo de Moura
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
static name * g_explicit_name = nullptr;
|
static name * g_explicit_name = nullptr;
|
||||||
|
static name * g_partial_explicit_name = nullptr;
|
||||||
static name * g_as_atomic_name = nullptr;
|
static name * g_as_atomic_name = nullptr;
|
||||||
static name * g_as_is_name = nullptr;
|
static name * g_as_is_name = nullptr;
|
||||||
static name * g_consume_args_name = nullptr;
|
static name * g_consume_args_name = nullptr;
|
||||||
|
@ -20,6 +21,11 @@ bool is_explicit(expr const & e) { return is_annotation(e, *g_explicit_name); }
|
||||||
bool is_nested_explicit(expr const & e) { return is_nested_annotation(e, *g_explicit_name); }
|
bool is_nested_explicit(expr const & e) { return is_nested_annotation(e, *g_explicit_name); }
|
||||||
expr const & get_explicit_arg(expr const & e) { lean_assert(is_explicit(e)); return get_annotation_arg(e); }
|
expr const & get_explicit_arg(expr const & e) { lean_assert(is_explicit(e)); return get_annotation_arg(e); }
|
||||||
|
|
||||||
|
expr mk_partial_explicit(expr const & e) { return mk_annotation(*g_partial_explicit_name, e); }
|
||||||
|
bool is_partial_explicit(expr const & e) { return is_annotation(e, *g_partial_explicit_name); }
|
||||||
|
bool is_nested_partial_explicit(expr const & e) { return is_nested_annotation(e, *g_partial_explicit_name); }
|
||||||
|
expr const & get_partial_explicit_arg(expr const & e) { lean_assert(is_partial_explicit(e)); return get_annotation_arg(e); }
|
||||||
|
|
||||||
expr mk_as_is(expr const & e) { return mk_annotation(*g_as_is_name, e); }
|
expr mk_as_is(expr const & e) { return mk_annotation(*g_as_is_name, e); }
|
||||||
bool is_as_is(expr const & e) { return is_annotation(e, *g_as_is_name); }
|
bool is_as_is(expr const & e) { return is_annotation(e, *g_as_is_name); }
|
||||||
expr const & get_as_is_arg(expr const & e) { lean_assert(is_as_is(e)); return get_annotation_arg(e); }
|
expr const & get_as_is_arg(expr const & e) { lean_assert(is_as_is(e)); return get_annotation_arg(e); }
|
||||||
|
@ -33,7 +39,8 @@ bool is_consume_args(expr const & e) { return is_annotation(e, *g_consume_args_n
|
||||||
expr const & get_consume_args_arg(expr const & e) { lean_assert(is_consume_args(e)); return get_annotation_arg(e); }
|
expr const & get_consume_args_arg(expr const & e) { lean_assert(is_consume_args(e)); return get_annotation_arg(e); }
|
||||||
|
|
||||||
void initialize_explicit() {
|
void initialize_explicit() {
|
||||||
g_explicit_name = new name("@");
|
g_explicit_name = new name("@@");
|
||||||
|
g_partial_explicit_name = new name("@");
|
||||||
g_as_atomic_name = new name("as_atomic");
|
g_as_atomic_name = new name("as_atomic");
|
||||||
g_as_is_name = new name("as_is");
|
g_as_is_name = new name("as_is");
|
||||||
g_consume_args_name = new name("!");
|
g_consume_args_name = new name("!");
|
||||||
|
@ -47,6 +54,7 @@ void initialize_explicit() {
|
||||||
void finalize_explicit() {
|
void finalize_explicit() {
|
||||||
delete g_as_is_name;
|
delete g_as_is_name;
|
||||||
delete g_as_atomic_name;
|
delete g_as_atomic_name;
|
||||||
|
delete g_partial_explicit_name;
|
||||||
delete g_explicit_name;
|
delete g_explicit_name;
|
||||||
delete g_consume_args_name;
|
delete g_consume_args_name;
|
||||||
}
|
}
|
||||||
|
@ -62,9 +70,24 @@ static int get_explicit_arg(lua_State * L) {
|
||||||
return push_expr(L, get_explicit_arg(to_expr(L, 1)));
|
return push_expr(L, get_explicit_arg(to_expr(L, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mk_partial_explicit(lua_State * L) { return push_expr(L, mk_partial_explicit(to_expr(L, 1))); }
|
||||||
|
static int is_partial_explicit(lua_State * L) { return push_boolean(L, is_partial_explicit(to_expr(L, 1))); }
|
||||||
|
static void check_partial_explicit(lua_State * L, int idx) {
|
||||||
|
if (!is_partial_explicit(to_expr(L, idx)))
|
||||||
|
throw exception(sstream() << "arg #" << idx << " is not a '@'-expression");
|
||||||
|
}
|
||||||
|
static int get_partial_explicit_arg(lua_State * L) {
|
||||||
|
check_partial_explicit(L, 1);
|
||||||
|
return push_expr(L, get_partial_explicit_arg(to_expr(L, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
void open_explicit(lua_State * L) {
|
void open_explicit(lua_State * L) {
|
||||||
SET_GLOBAL_FUN(mk_explicit, "mk_explicit");
|
SET_GLOBAL_FUN(mk_explicit, "mk_explicit");
|
||||||
SET_GLOBAL_FUN(is_explicit, "is_explicit");
|
SET_GLOBAL_FUN(is_explicit, "is_explicit");
|
||||||
SET_GLOBAL_FUN(get_explicit_arg, "get_explicit_arg");
|
SET_GLOBAL_FUN(get_explicit_arg, "get_explicit_arg");
|
||||||
|
|
||||||
|
SET_GLOBAL_FUN(mk_partial_explicit, "mk_partial_explicit");
|
||||||
|
SET_GLOBAL_FUN(is_partial_explicit, "is_partial_explicit");
|
||||||
|
SET_GLOBAL_FUN(get_partial_explicit_arg, "get_partial_explicit_arg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ Author: Leonardo de Moura
|
||||||
#include "kernel/expr.h"
|
#include "kernel/expr.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
/** \brief Create an explicit expression '@ f'.
|
/** \brief Create an explicit expression '@@ f'.
|
||||||
This only affects the elaborator behavior.
|
This only affects the elaborator behavior.
|
||||||
*/
|
*/
|
||||||
expr mk_explicit(expr const & e);
|
expr mk_explicit(expr const & e);
|
||||||
|
@ -22,6 +22,20 @@ bool is_nested_explicit(expr const & e);
|
||||||
*/
|
*/
|
||||||
expr const & get_explicit_arg(expr const & e);
|
expr const & get_explicit_arg(expr const & e);
|
||||||
|
|
||||||
|
/** \brief Create an partial explicit expression '@ f'.
|
||||||
|
This only affects the elaborator behavior.
|
||||||
|
*/
|
||||||
|
expr mk_partial_explicit(expr const & e);
|
||||||
|
/** \brief Return true iff \c e is a partial explicit expression. */
|
||||||
|
bool is_partial_explicit(expr const & e);
|
||||||
|
/** \brief See #is_nested_annotation */
|
||||||
|
bool is_nested_partial_explicit(expr const & e);
|
||||||
|
/** \brief Return the argument of a partial explicit expression.
|
||||||
|
\pre is_partial_explicit(e)
|
||||||
|
*/
|
||||||
|
expr const & get_partial_explicit_arg(expr const & e);
|
||||||
|
|
||||||
|
|
||||||
/** \brief Create an explicit expression that is accepted as is
|
/** \brief Create an explicit expression that is accepted as is
|
||||||
by the elaborator.
|
by the elaborator.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue