287 in |
287 in |
288 th |> forall_intr_list dom |
288 th |> forall_intr_list dom |
289 |> forall_elim_list rng |
289 |> forall_elim_list rng |
290 end |
290 end |
291 |
291 |
292 val transl_dot = String.translate (fn #"." => "dot" | c => Char.toString c) |
292 val make_name = String.translate (fn #"." => "dot" | c => Char.toString c) |
293 |
293 |
294 val transl_qm = String.translate (fn #"?" => "t" | c => Char.toString c) |
294 fun make_free (x, ty) = Free (make_name x, ty) |
295 |
295 |
296 fun getconstname s thy = |
296 fun make_tfree a = |
297 case Import_Data.get_const_map s thy of |
297 let val b = "'" ^ String.translate (fn #"?" => "t" | c => Char.toString c) a |
298 SOME s => s |
298 in TFree (b, \<^sort>\<open>type\<close>) end |
299 | NONE => Sign.full_name thy (Binding.name (transl_dot s)) |
299 |
|
300 fun make_const thy (c, ty) = |
|
301 let |
|
302 val d = |
|
303 (case Import_Data.get_const_map c thy of |
|
304 SOME d => d |
|
305 | NONE => Sign.full_name thy (Binding.name (make_name c))) |
|
306 in Const (d, ty) end |
|
307 |
300 fun gettyname s thy = |
308 fun gettyname s thy = |
301 case Import_Data.get_typ_map s thy of |
309 case Import_Data.get_typ_map s thy of |
302 SOME s => s |
310 SOME s => s |
303 | NONE => Sign.full_name thy (Binding.name s) |
311 | NONE => Sign.full_name thy (Binding.name s) |
304 |
312 |
396 setth (inst (pairList tms) th) tstate |
404 setth (inst (pairList tms) th) tstate |
397 end |
405 end |
398 | process tstate (#"F", [name, t]) = |
406 | process tstate (#"F", [name, t]) = |
399 let |
407 let |
400 val (tm, (thy, state)) = gettm t tstate |
408 val (tm, (thy, state)) = gettm t tstate |
401 val (th, thy) = def (transl_dot name) tm thy |
409 val (th, thy) = def (make_name name) tm thy |
402 in |
410 in |
403 setth th (thy, state) |
411 setth th (thy, state) |
404 end |
412 end |
405 | process (thy, state) (#"F", [name]) = setth (mdef name thy) (thy, state) |
413 | process (thy, state) (#"F", [name]) = setth (mdef name thy) (thy, state) |
406 | process tstate (#"Y", [name, absname, repname, t1, t2, th]) = |
414 | process tstate (#"Y", [name, absname, repname, t1, t2, th]) = |
412 in |
420 in |
413 setth th (thy, state) |
421 setth th (thy, state) |
414 end |
422 end |
415 | process (thy, state) (#"Y", [name, _, _]) = setth (mtydef name thy) (thy, state) |
423 | process (thy, state) (#"Y", [name, _, _]) = setth (mtydef name thy) (thy, state) |
416 | process (thy, state) (#"t", [n]) = |
424 | process (thy, state) (#"t", [n]) = |
417 setty (Thm.global_ctyp_of thy (TFree ("'" ^ transl_qm n, \<^sort>\<open>type\<close>))) (thy, state) |
425 setty (Thm.global_ctyp_of thy (make_tfree n)) (thy, state) |
418 | process (thy, state) (#"a", n :: l) = |
426 | process (thy, state) (#"a", n :: l) = |
419 fold_map getty l (thy, state) |>> |
427 fold_map getty l (thy, state) |>> |
420 (fn tys => Thm.global_ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty |
428 (fn tys => Thm.global_ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty |
421 | process (thy, state) (#"v", [n, ty]) = |
429 | process (thy, state) (#"v", [n, ty]) = |
422 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Free (transl_dot n, Thm.typ_of ty))) |-> settm |
430 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (make_free (n, Thm.typ_of ty))) |-> settm |
423 | process (thy, state) (#"c", [n, ty]) = |
431 | process (thy, state) (#"c", [n, ty]) = |
424 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Const (getconstname n thy, Thm.typ_of ty))) |-> settm |
432 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (make_const thy (n, Thm.typ_of ty))) |-> settm |
425 | process tstate (#"f", [t1, t2]) = |
433 | process tstate (#"f", [t1, t2]) = |
426 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.apply t1 t2) |-> settm |
434 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.apply t1 t2) |-> settm |
427 | process tstate (#"l", [t1, t2]) = |
435 | process tstate (#"l", [t1, t2]) = |
428 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.lambda t1 t2) |-> settm |
436 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.lambda t1 t2) |-> settm |
429 | process (thy, state) (#"+", [s]) = |
437 | process (thy, state) (#"+", [s]) = |
430 (store_thm (Binding.name (transl_dot s)) (last_thm state) thy, state) |
438 (store_thm (Binding.name (make_name s)) (last_thm state) thy, state) |
431 | process _ (c, _) = error ("process: unknown command: " ^ String.implode [c]) |
439 | process _ (c, _) = error ("process: unknown command: " ^ String.implode [c]) |
432 |
440 |
433 fun parse_line s = |
441 fun parse_line s = |
434 case String.tokens (fn x => (x = #"\n" orelse x = #" ")) s of |
442 case String.tokens (fn x => (x = #"\n" orelse x = #" ")) s of |
435 [] => error "parse_line: empty" |
443 [] => error "parse_line: empty" |