src/Pure/Syntax/syntax.ML
changeset 25060 17c313217998
parent 25043 32ed65dc1bf4
child 25122 f37d7dd25c88
equal deleted inserted replaced
25059:e6e0ee56a672 25060:17c313217998
   103     unparse_sort: Proof.context -> sort -> Pretty.T,
   103     unparse_sort: Proof.context -> sort -> Pretty.T,
   104     unparse_typ: Proof.context -> typ -> Pretty.T,
   104     unparse_typ: Proof.context -> typ -> Pretty.T,
   105     unparse_term: Proof.context -> term -> Pretty.T} -> unit
   105     unparse_term: Proof.context -> term -> Pretty.T} -> unit
   106   val print_checks: Proof.context -> unit
   106   val print_checks: Proof.context -> unit
   107   val add_typ_check: int -> string ->
   107   val add_typ_check: int -> string ->
   108     (typ list -> Proof.context -> typ list * Proof.context) ->
   108     (typ list -> Proof.context -> (typ list * Proof.context) option) ->
   109     Context.generic -> Context.generic
   109     Context.generic -> Context.generic
   110   val add_term_check: int -> string ->
   110   val add_term_check: int -> string ->
   111     (term list -> Proof.context -> term list * Proof.context) ->
   111     (term list -> Proof.context -> (term list * Proof.context) option) ->
   112     Context.generic -> Context.generic
   112     Context.generic -> Context.generic
   113   val add_typ_uncheck: int -> string ->
   113   val add_typ_uncheck: int -> string ->
   114     (typ list -> Proof.context -> typ list * Proof.context) ->
   114     (typ list -> Proof.context -> (typ list * Proof.context) option) ->
   115     Context.generic -> Context.generic
   115     Context.generic -> Context.generic
   116   val add_term_uncheck: int -> string ->
   116   val add_term_uncheck: int -> string ->
   117     (term list -> Proof.context -> term list * Proof.context) ->
   117     (term list -> Proof.context -> (term list * Proof.context) option) ->
   118     Context.generic -> Context.generic
   118     Context.generic -> Context.generic
   119   val check_sort: Proof.context -> sort -> sort
   119   val check_sort: Proof.context -> sort -> sort
   120   val check_typ: Proof.context -> typ -> typ
   120   val check_typ: Proof.context -> typ -> typ
   121   val check_term: Proof.context -> term -> term
   121   val check_term: Proof.context -> term -> term
   122   val check_prop: Proof.context -> term -> term
   122   val check_prop: Proof.context -> term -> term
   682 (* context-sensitive (un)checking *)
   682 (* context-sensitive (un)checking *)
   683 
   683 
   684 local
   684 local
   685 
   685 
   686 type key = int * bool;
   686 type key = int * bool;
   687 type 'a check = 'a list -> Proof.context -> 'a list * Proof.context;
   687 type 'a check = 'a list -> Proof.context -> ('a list * Proof.context) option;
   688 
   688 
   689 structure Checks = GenericDataFun
   689 structure Checks = GenericDataFun
   690 (
   690 (
   691   type T =
   691   type T =
   692     ((key * ((string * typ check) * stamp) list) list *
   692     ((key * ((string * typ check) * stamp) list) list *
   699 );
   699 );
   700 
   700 
   701 fun gen_add which (key: key) name f =
   701 fun gen_add which (key: key) name f =
   702   Checks.map (which (AList.map_default op = (key, []) (cons ((name, f), stamp ()))));
   702   Checks.map (which (AList.map_default op = (key, []) (cons ((name, f), stamp ()))));
   703 
   703 
   704 fun gen_check which uncheck eq ctxt0 xs0 =
   704 fun check_stage fs = perhaps_loop (perhaps_apply (map uncurry fs));
       
   705 
       
   706 fun gen_check which uncheck ctxt0 xs0 =
   705   let
   707   let
   706     val funs = which (Checks.get (Context.Proof ctxt0))
   708     val funs = which (Checks.get (Context.Proof ctxt0))
   707       |> map_filter (fn ((i, u), fs) => if uncheck = u then SOME (i, map (snd o fst) fs) else NONE)
   709       |> map_filter (fn ((i, u), fs) => if uncheck = u then SOME (i, map (snd o fst) fs) else NONE)
   708       |> Library.sort (int_ord o pairself fst)
   710       |> Library.sort (int_ord o pairself fst) |> map snd
   709       |> not uncheck ? map (apsnd rev);
   711       |> not uncheck ? map rev;
   710 
   712     val check_all = perhaps_apply (map check_stage funs);
   711     fun check_fixpoint fs (xs, ctxt) =
   713   in #1 (perhaps check_all (xs0, ctxt0)) end;
   712       let val (xs', ctxt') = fold uncurry fs (xs, ctxt) in
       
   713         if eq_list eq (xs, xs') then (xs, ctxt)
       
   714         else check_fixpoint fs (xs', ctxt')
       
   715       end;
       
   716   in #1 (fold (check_fixpoint o snd) funs (xs0, ctxt0)) end;
       
   717 
   714 
   718 fun map_sort f S =
   715 fun map_sort f S =
   719   (case f (TFree ("", S)) of
   716   (case f (TFree ("", S)) of
   720     TFree ("", S') => S'
   717     TFree ("", S') => S'
   721   | _ => raise TYPE ("map_sort", [TFree ("", S)], []));
   718   | _ => raise TYPE ("map_sort", [TFree ("", S)], []));
   746 fun add_typ_check stage = gen_add apfst (stage, false);
   743 fun add_typ_check stage = gen_add apfst (stage, false);
   747 fun add_term_check stage = gen_add apsnd (stage, false);
   744 fun add_term_check stage = gen_add apsnd (stage, false);
   748 fun add_typ_uncheck stage = gen_add apfst (stage, true);
   745 fun add_typ_uncheck stage = gen_add apfst (stage, true);
   749 fun add_term_uncheck stage = gen_add apsnd (stage, true);
   746 fun add_term_uncheck stage = gen_add apsnd (stage, true);
   750 
   747 
   751 val check_typs = gen_check fst false (op =);
   748 val check_typs = gen_check fst false;
   752 val check_terms = gen_check snd false (op aconv);
   749 val check_terms = gen_check snd false;
   753 fun check_props ctxt = map (TypeInfer.constrain propT) #> check_terms ctxt;
   750 fun check_props ctxt = map (TypeInfer.constrain propT) #> check_terms ctxt;
   754 
   751 
   755 val check_typ = singleton o check_typs;
   752 val check_typ = singleton o check_typs;
   756 val check_term = singleton o check_terms;
   753 val check_term = singleton o check_terms;
   757 val check_prop = singleton o check_props;
   754 val check_prop = singleton o check_props;
   758 val check_sort = map_sort o check_typ;
   755 val check_sort = map_sort o check_typ;
   759 
   756 
   760 val uncheck_typs = gen_check fst true (op =);
   757 val uncheck_typs = gen_check fst true;
   761 val uncheck_terms = gen_check snd true (op aconv);
   758 val uncheck_terms = gen_check snd true;
   762 val uncheck_sort = map_sort o singleton o uncheck_typs;
   759 val uncheck_sort = map_sort o singleton o uncheck_typs;
   763 
   760 
   764 end;
   761 end;
   765 
   762 
   766 
   763