src/Pure/Isar/expression.ML
changeset 30786 461f7b5f16a2
parent 30784 bd879a0e1f89
child 31977 e03059ae2d82
child 31988 801aabf9f376
equal deleted inserted replaced
30785:15f64e05e703 30786:461f7b5f16a2
   333 (* Interleave incremental parsing and type inference over entire parsed stretch. *)
   333 (* Interleave incremental parsing and type inference over entire parsed stretch. *)
   334 
   334 
   335 local
   335 local
   336 
   336 
   337 fun prep_full_context_statement parse_typ parse_prop prep_vars_elem prep_inst prep_vars_inst prep_expr
   337 fun prep_full_context_statement parse_typ parse_prop prep_vars_elem prep_inst prep_vars_inst prep_expr
   338     strict do_close raw_import init_body raw_elems raw_concl ctxt1 =
   338     {strict, do_close, fixed_frees} raw_import init_body raw_elems raw_concl ctxt1 =
   339   let
   339   let
   340     val thy = ProofContext.theory_of ctxt1;
   340     val thy = ProofContext.theory_of ctxt1;
   341 
   341 
   342     val (raw_insts, fixed) = parameters_of thy strict (apfst (prep_expr thy) raw_import);
   342     val (raw_insts, fixed) = parameters_of thy strict (apfst (prep_expr thy) raw_import);
   343 
   343 
   368       in check_autofix insts elems concl ctxt end;
   368       in check_autofix insts elems concl ctxt end;
   369 
   369 
   370     val fors = prep_vars_inst fixed ctxt1 |> fst;
   370     val fors = prep_vars_inst fixed ctxt1 |> fst;
   371     val ctxt2 = ctxt1 |> ProofContext.add_fixes fors |> snd;
   371     val ctxt2 = ctxt1 |> ProofContext.add_fixes fors |> snd;
   372     val (_, insts', ctxt3) = fold prep_insts_cumulative raw_insts (0, [], ctxt2);
   372     val (_, insts', ctxt3) = fold prep_insts_cumulative raw_insts (0, [], ctxt2);
       
   373 
       
   374     val add_free = fold_aterms
       
   375       (fn Free (x, T) => not (Variable.is_fixed ctxt3 x) ? insert (op =) (x, T) | _ => I);
       
   376     val _ =
       
   377       if fixed_frees then ()
       
   378       else
       
   379         (case fold (fold add_free o snd o snd) insts' [] of
       
   380           [] => ()
       
   381         | frees => error ("Illegal free variables in expression: " ^
       
   382             commas_quote (map (Syntax.string_of_term ctxt3 o Free) (rev frees))));
       
   383 
   373     val ctxt4 = init_body ctxt3;
   384     val ctxt4 = init_body ctxt3;
   374     val (elems, ctxt5) = fold (prep_elem insts') raw_elems ([], ctxt4);
   385     val (elems, ctxt5) = fold (prep_elem insts') raw_elems ([], ctxt4);
   375     val (insts, elems', concl, ctxt6) = prep_concl raw_concl (insts', elems, ctxt5);
   386     val (insts, elems', concl, ctxt6) = prep_concl raw_concl (insts', elems, ctxt5);
   376 
   387 
   377     (* Retrieve parameter types *)
   388     (* Retrieve parameter types *)
   408 local
   419 local
   409 
   420 
   410 fun prep_statement prep activate raw_elems raw_concl context =
   421 fun prep_statement prep activate raw_elems raw_concl context =
   411   let
   422   let
   412      val ((_, _, elems, concl), _) =
   423      val ((_, _, elems, concl), _) =
   413        prep true false ([], []) I raw_elems raw_concl context;
   424        prep {strict = true, do_close = false, fixed_frees = true}
       
   425         ([], []) I raw_elems raw_concl context;
   414      val (_, context') = context |>
   426      val (_, context') = context |>
   415        ProofContext.set_stmt true |>
   427        ProofContext.set_stmt true |>
   416        fold_map activate elems;
   428        fold_map activate elems;
   417   in (concl, context') end;
   429   in (concl, context') end;
   418 
   430 
   432 local
   444 local
   433 
   445 
   434 fun prep_declaration prep activate raw_import init_body raw_elems context =
   446 fun prep_declaration prep activate raw_import init_body raw_elems context =
   435   let
   447   let
   436     val ((fixed, deps, elems, _), (parms, ctxt')) =
   448     val ((fixed, deps, elems, _), (parms, ctxt')) =
   437       prep false true raw_import init_body raw_elems [] context ;
   449       prep {strict = false, do_close = true, fixed_frees = false}
       
   450         raw_import init_body raw_elems [] context;
   438     (* Declare parameters and imported facts *)
   451     (* Declare parameters and imported facts *)
   439     val context' = context |>
   452     val context' = context |>
   440       fix_params fixed |>
   453       fix_params fixed |>
   441       fold (Context.proof_map o Locale.activate_facts) deps;
   454       fold (Context.proof_map o Locale.activate_facts) deps;
   442     val (elems', _) = context' |>
   455     val (elems', _) = context' |>
   467 fun prep_goal_expression prep expression context =
   480 fun prep_goal_expression prep expression context =
   468   let
   481   let
   469     val thy = ProofContext.theory_of context;
   482     val thy = ProofContext.theory_of context;
   470 
   483 
   471     val ((fixed, deps, _, _), _) =
   484     val ((fixed, deps, _, _), _) =
   472       prep true true expression I [] [] context;
   485       prep {strict = true, do_close = true, fixed_frees = true} expression I [] [] context;
   473     (* proof obligations *)
   486     (* proof obligations *)
   474     val propss = map (props_of thy) deps;
   487     val propss = map (props_of thy) deps;
   475 
   488 
   476     val goal_ctxt = context |>
   489     val goal_ctxt = context |>
   477       fix_params fixed |>
   490       fix_params fixed |>