fix(frontends/lean/builtin_cmds): allow coercion command inside section, fixes #186

This commit is contained in:
Leonardo de Moura 2014-09-12 12:13:29 -07:00
parent a305012ce5
commit a2e36e97f2
2 changed files with 13 additions and 10 deletions

View file

@ -295,19 +295,13 @@ environment open_cmd(parser & p) { return open_export_cmd(p, true); }
environment export_cmd(parser & p) { return open_export_cmd(p, false); } environment export_cmd(parser & p) { return open_export_cmd(p, false); }
environment coercion_cmd(parser & p) { environment coercion_cmd(parser & p) {
auto pos = p.pos(); name f = p.check_constant_next("invalid 'coercion' command, constant expected");
expr f = p.parse_expr();
if (!is_constant(f))
throw parser_error("invalid 'coercion' command, constant expected", pos);
if (p.curr_is_token(g_colon)) { if (p.curr_is_token(g_colon)) {
p.next(); p.next();
pos = p.pos(); name C = p.check_constant_next("invalid 'coercion' command, constant expected");
expr C = p.parse_expr(); return add_coercion(p.env(), f, C, p.ios());
if (!is_constant(C))
throw parser_error("invalid 'coercion' command, constant expected", pos);
return add_coercion(p.env(), const_name(f), const_name(C), p.ios());
} else { } else {
return add_coercion(p.env(), const_name(f), p.ios()); return add_coercion(p.env(), f, p.ios());
} }
} }

View file

@ -0,0 +1,9 @@
inductive func (A B : Type) :=
mk : (A → B) → func A B
section
parameters {A B : Type}
definition to_function (F : func A B) : A → B :=
func.rec (λf, f) F
coercion to_function
end