src/HOL/Import/import_syntax.ML
changeset 14620 1be590fd2422
parent 14518 c3019a66180f
child 14627 5d137da82f03
equal deleted inserted replaced
14619:8876ad83b1fb 14620:1be590fd2422
       
     1 (*  Title:      HOL/Import/import_syntax.ML
       
     2     ID:         $Id$
       
     3     Author:     Sebastian Skalberg (TU Muenchen)
       
     4 *)
       
     5 
     1 signature HOL4_IMPORT_SYNTAX =
     6 signature HOL4_IMPORT_SYNTAX =
     2 sig
     7 sig
     3     type token = OuterSyntax.token
     8     type token = OuterSyntax.token
     4 
     9 
     5     val import_segment: token list -> (theory -> theory) * token list
    10     val import_segment: token list -> (theory -> theory) * token list
   148 	  | apply (f::fs) thy = apply fs (f thy)
   153 	  | apply (f::fs) thy = apply fs (f thy)
   149     in
   154     in
   150 	apply (set_replaying_thy s::Theory.add_path s::(fst (importP token_list)))
   155 	apply (set_replaying_thy s::Theory.add_path s::(fst (importP token_list)))
   151     end
   156     end
   152 
   157 
       
   158 fun create_int_thms thyname thy =
       
   159     case ImportData.get thy of
       
   160 	None => ImportData.put (Some (fst (Replay.setup_int_thms thyname thy))) thy
       
   161       | Some _ => error "Import data not closed - forgotten an end_setup, mayhap?"
       
   162 
       
   163 fun clear_int_thms thy =
       
   164     case ImportData.get thy of
       
   165 	None => error "Import data already cleared - forgotten a setup_theory?"
       
   166       | Some _ => ImportData.put None thy
       
   167 
   153 val setup_theory = P.name
   168 val setup_theory = P.name
   154 		       >>
   169 		       >>
   155 		       (fn thyname =>
   170 		       (fn thyname =>
   156 			fn thy =>
   171 			fn thy =>
   157 			   case HOL4DefThy.get thy of
   172 			   (case HOL4DefThy.get thy of
   158 			       NoImport => thy |> import_thy thyname
   173 				NoImport => thy
   159 			     | Generating _ => error "Currently generating a theory!"
   174 			      | Generating _ => error "Currently generating a theory!"
   160 			     | Replaying _ => thy |> clear_import_thy |> import_thy thyname)
   175 			      | Replaying _ => thy |> clear_import_thy)
       
   176 			       |> import_thy thyname
       
   177 			       |> create_int_thms thyname)
   161 
   178 
   162 fun end_setup toks =
   179 fun end_setup toks =
   163     Scan.succeed
   180     Scan.succeed
   164 	(fn thy =>
   181 	(fn thy =>
   165 	    let
   182 	    let
   166 		val thyname = get_import_thy thy
   183 		val thyname = get_import_thy thy
   167 		val segname = get_import_segment thy
   184 		val segname = get_import_segment thy
   168 	    in
   185 	    in
   169 		thy |> set_segment thyname segname
   186 		thy |> set_segment thyname segname
   170 		    |> clear_import_thy
   187 		    |> clear_import_thy
       
   188 		    |> clear_int_thms
   171 		    |> Theory.parent_path
   189 		    |> Theory.parent_path
   172 	    end) toks
   190 	    end) toks
   173 
   191 
   174 val set_dump  = P.string -- P.string   >> setup_dump
   192 val set_dump  = P.string -- P.string   >> setup_dump
   175 fun fl_dump toks  = Scan.succeed flush_dump toks
   193 fun fl_dump toks  = Scan.succeed flush_dump toks