feat(frontends/lean/decl_cmds): allow 'empty' set of pattern matching equations
This commit is contained in:
parent
8e9ccf8b6f
commit
28487ede3b
3 changed files with 63 additions and 48 deletions
|
@ -119,7 +119,7 @@
|
||||||
;; modifiers
|
;; modifiers
|
||||||
(,(rx (or "\[persistent\]" "\[notation\]" "\[visible\]" "\[instance\]" "\[class\]" "\[parsing-only\]"
|
(,(rx (or "\[persistent\]" "\[notation\]" "\[visible\]" "\[instance\]" "\[class\]" "\[parsing-only\]"
|
||||||
"\[coercion\]" "\[reducible\]" "\[irreducible\]" "\[semireducible\]" "\[quasireducible\]" "\[wf\]"
|
"\[coercion\]" "\[reducible\]" "\[irreducible\]" "\[semireducible\]" "\[quasireducible\]" "\[wf\]"
|
||||||
"\[whnf\]" "\[multiple-instances\]"
|
"\[whnf\]" "\[multiple-instances\]" "\[none\]"
|
||||||
"\[decls\]" "\[declarations\]" "\[all-transparent\]" "\[coercions\]" "\[classes\]"
|
"\[decls\]" "\[declarations\]" "\[all-transparent\]" "\[coercions\]" "\[classes\]"
|
||||||
"\[notations\]" "\[abbreviations\]" "\[begin-end-hints\]" "\[tactic-hints\]" "\[reduce-hints\]"))
|
"\[notations\]" "\[abbreviations\]" "\[begin-end-hints\]" "\[tactic-hints\]" "\[reduce-hints\]"))
|
||||||
. 'font-lock-doc-face)
|
. 'font-lock-doc-face)
|
||||||
|
|
|
@ -604,58 +604,64 @@ expr parse_equations(parser & p, name const & n, expr const & type, buffer<name>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_eqn_prefix(p);
|
check_eqn_prefix(p);
|
||||||
for (expr const & fn : fns)
|
if (p.curr_is_token(get_none_tk())) {
|
||||||
p.add_local(fn);
|
// no equations have been provided
|
||||||
while (true) {
|
p.next();
|
||||||
expr lhs;
|
eqns.push_back(Fun(fns, mk_no_equation(), p));
|
||||||
unsigned prev_num_undef_ids = p.get_num_undef_ids();
|
} else {
|
||||||
buffer<expr> locals;
|
for (expr const & fn : fns)
|
||||||
{
|
p.add_local(fn);
|
||||||
parser::undef_id_to_local_scope scope2(p);
|
while (true) {
|
||||||
buffer<expr> lhs_args;
|
expr lhs;
|
||||||
auto lhs_pos = p.pos();
|
unsigned prev_num_undef_ids = p.get_num_undef_ids();
|
||||||
if (p.curr_is_token(get_explicit_tk())) {
|
buffer<expr> locals;
|
||||||
p.next();
|
{
|
||||||
name fn_name = p.check_id_next("invalid recursive equation, identifier expected");
|
parser::undef_id_to_local_scope scope2(p);
|
||||||
lhs_args.push_back(p.save_pos(mk_explicit(get_equation_fn(fns, fn_name, lhs_pos)), lhs_pos));
|
buffer<expr> lhs_args;
|
||||||
} else {
|
auto lhs_pos = p.pos();
|
||||||
expr first = p.parse_expr(get_max_prec());
|
if (p.curr_is_token(get_explicit_tk())) {
|
||||||
expr fn = first;
|
p.next();
|
||||||
if (is_explicit(fn))
|
name fn_name = p.check_id_next("invalid recursive equation, identifier expected");
|
||||||
fn = get_explicit_arg(fn);
|
lhs_args.push_back(p.save_pos(mk_explicit(get_equation_fn(fns, fn_name, lhs_pos)), lhs_pos));
|
||||||
if (is_local(fn) && is_equation_fn(fns, local_pp_name(fn))) {
|
|
||||||
lhs_args.push_back(first);
|
|
||||||
} else if (fns.size() == 1) {
|
|
||||||
lhs_args.push_back(p.save_pos(mk_explicit(fns[0]), lhs_pos));
|
|
||||||
lhs_args.push_back(first);
|
|
||||||
} else {
|
} else {
|
||||||
throw parser_error("invalid recursive equation, head symbol in left-hand-side is not a constant",
|
expr first = p.parse_expr(get_max_prec());
|
||||||
lhs_pos);
|
expr fn = first;
|
||||||
|
if (is_explicit(fn))
|
||||||
|
fn = get_explicit_arg(fn);
|
||||||
|
if (is_local(fn) && is_equation_fn(fns, local_pp_name(fn))) {
|
||||||
|
lhs_args.push_back(first);
|
||||||
|
} else if (fns.size() == 1) {
|
||||||
|
lhs_args.push_back(p.save_pos(mk_explicit(fns[0]), lhs_pos));
|
||||||
|
lhs_args.push_back(first);
|
||||||
|
} else {
|
||||||
|
throw parser_error("invalid recursive equation, head symbol in left-hand-side is not a constant",
|
||||||
|
lhs_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!p.curr_is_token(get_assign_tk()))
|
||||||
|
lhs_args.push_back(p.parse_expr(get_max_prec()));
|
||||||
|
lhs = p.save_pos(mk_app(lhs_args.size(), lhs_args.data()), lhs_pos);
|
||||||
|
|
||||||
|
unsigned num_undef_ids = p.get_num_undef_ids();
|
||||||
|
for (unsigned i = prev_num_undef_ids; i < num_undef_ids; i++) {
|
||||||
|
locals.push_back(p.get_undef_id(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!p.curr_is_token(get_assign_tk()))
|
validate_equation_lhs(p, lhs, locals);
|
||||||
lhs_args.push_back(p.parse_expr(get_max_prec()));
|
lhs = merge_equation_lhs_vars(lhs, locals);
|
||||||
lhs = p.save_pos(mk_app(lhs_args.size(), lhs_args.data()), lhs_pos);
|
auto assign_pos = p.pos();
|
||||||
|
p.check_token_next(get_assign_tk(), "invalid declaration, ':=' expected");
|
||||||
unsigned num_undef_ids = p.get_num_undef_ids();
|
{
|
||||||
for (unsigned i = prev_num_undef_ids; i < num_undef_ids; i++) {
|
parser::local_scope scope2(p);
|
||||||
locals.push_back(p.get_undef_id(i));
|
for (expr const & local : locals)
|
||||||
|
p.add_local(local);
|
||||||
|
expr rhs = p.parse_expr();
|
||||||
|
eqns.push_back(Fun(fns, Fun(locals, p.save_pos(mk_equation(lhs, rhs), assign_pos), p)));
|
||||||
}
|
}
|
||||||
|
if (!is_eqn_prefix(p))
|
||||||
|
break;
|
||||||
|
p.next();
|
||||||
}
|
}
|
||||||
validate_equation_lhs(p, lhs, locals);
|
|
||||||
lhs = merge_equation_lhs_vars(lhs, locals);
|
|
||||||
auto assign_pos = p.pos();
|
|
||||||
p.check_token_next(get_assign_tk(), "invalid declaration, ':=' expected");
|
|
||||||
{
|
|
||||||
parser::local_scope scope2(p);
|
|
||||||
for (expr const & local : locals)
|
|
||||||
p.add_local(local);
|
|
||||||
expr rhs = p.parse_expr();
|
|
||||||
eqns.push_back(Fun(fns, Fun(locals, p.save_pos(mk_equation(lhs, rhs), assign_pos), p)));
|
|
||||||
}
|
|
||||||
if (!is_eqn_prefix(p))
|
|
||||||
break;
|
|
||||||
p.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p.curr_is_token(get_wf_tk())) {
|
if (p.curr_is_token(get_wf_tk())) {
|
||||||
|
|
9
tests/lean/run/empty_eq.lean
Normal file
9
tests/lean/run/empty_eq.lean
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import data.fin
|
||||||
|
open nat
|
||||||
|
open fin
|
||||||
|
|
||||||
|
definition case0 {C : fin zero → Type} : Π (f : fin zero), C f
|
||||||
|
| [none]
|
||||||
|
|
||||||
|
|
||||||
|
print definition case0
|
Loading…
Reference in a new issue