43 val split_simproc: (term -> int) -> simproc |
43 val split_simproc: (term -> int) -> simproc |
44 val ex_sel_eq_simproc: simproc |
44 val ex_sel_eq_simproc: simproc |
45 val split_tac: Proof.context -> int -> tactic |
45 val split_tac: Proof.context -> int -> tactic |
46 val split_simp_tac: Proof.context -> thm list -> (term -> int) -> int -> tactic |
46 val split_simp_tac: Proof.context -> thm list -> (term -> int) -> int -> tactic |
47 val split_wrapper: string * (Proof.context -> wrapper) |
47 val split_wrapper: string * (Proof.context -> wrapper) |
|
48 |
|
49 val pretty_recT: Proof.context -> typ -> Pretty.T |
|
50 val string_of_record: Proof.context -> string -> string |
48 |
51 |
49 val codegen: bool Config.T |
52 val codegen: bool Config.T |
50 val updateN: string |
53 val updateN: string |
51 val ext_typeN: string |
54 val ext_typeN: string |
52 val extN: string |
55 val extN: string |
2348 in thy |> add_record overloaded (params', binding) parent fields end; |
2351 in thy |> add_record overloaded (params', binding) parent fields end; |
2349 |
2352 |
2350 end; |
2353 end; |
2351 |
2354 |
2352 |
2355 |
|
2356 (* printing *) |
|
2357 |
|
2358 local |
|
2359 |
|
2360 fun the_parent_recT (Type (parent, [Type (_, [unit as Type (_,[])])])) = Type (parent, [unit]) |
|
2361 | the_parent_recT (Type (extT, [T])) = Type (extT, [the_parent_recT T]) |
|
2362 | the_parent_recT T = raise TYPE ("Not a unit record scheme with parent: ", [T], []) |
|
2363 |
|
2364 in |
|
2365 |
|
2366 fun pretty_recT ctxt typ = |
|
2367 let |
|
2368 val thy = Proof_Context.theory_of ctxt |
|
2369 val (fs, (_, moreT)) = get_recT_fields thy typ |
|
2370 val _ = if moreT = HOLogic.unitT then () else raise TYPE ("Not a unit record scheme: ", [typ], []) |
|
2371 val parent = if length (dest_recTs typ) >= 2 then SOME (the_parent_recT typ) else NONE |
|
2372 val pfs = case parent of SOME p => fst (get_recT_fields thy p) | NONE => [] |
|
2373 val fs' = drop (length pfs) fs |
|
2374 fun pretty_field (name, typ) = Pretty.block [ |
|
2375 Syntax.pretty_term ctxt (Const (name, typ)), |
|
2376 Pretty.brk 1, |
|
2377 Pretty.str "::", |
|
2378 Pretty.brk 1, |
|
2379 Syntax.pretty_typ ctxt typ |
|
2380 ] |
|
2381 in |
|
2382 Pretty.block (Library.separate (Pretty.brk 1) |
|
2383 ([Pretty.keyword1 "record", Syntax.pretty_typ ctxt typ, Pretty.str "="] @ |
|
2384 (case parent of |
|
2385 SOME p => [Syntax.pretty_typ ctxt p, Pretty.str "+"] |
|
2386 | NONE => [])) @ |
|
2387 Pretty.fbrk :: |
|
2388 Pretty.fbreaks (map pretty_field fs')) |
|
2389 end |
|
2390 |
|
2391 end |
|
2392 |
|
2393 fun string_of_record ctxt s = |
|
2394 let |
|
2395 val T = Syntax.read_typ ctxt s |
|
2396 in |
|
2397 Pretty.string_of (pretty_recT ctxt T) |
|
2398 handle TYPE _ => error ("Unknown record: " ^ Syntax.string_of_typ ctxt T) |
|
2399 end |
|
2400 |
|
2401 val print_record = |
|
2402 let |
|
2403 fun print_item string_of (modes, arg) = Toplevel.keep (fn state => |
|
2404 Print_Mode.with_modes modes (fn () => Output.writeln (string_of state arg)) ()); |
|
2405 in print_item (string_of_record o Toplevel.context_of) end |
|
2406 |
|
2407 |
2353 (* outer syntax *) |
2408 (* outer syntax *) |
2354 |
2409 |
2355 val _ = |
2410 val _ = |
2356 Outer_Syntax.command @{command_keyword record} "define extensible record" |
2411 Outer_Syntax.command @{command_keyword record} "define extensible record" |
2357 (Parse_Spec.overloaded -- (Parse.type_args_constrained -- Parse.binding) -- |
2412 (Parse_Spec.overloaded -- (Parse.type_args_constrained -- Parse.binding) -- |
2358 (@{keyword "="} |-- Scan.option (Parse.typ --| @{keyword "+"}) -- |
2413 (@{keyword "="} |-- Scan.option (Parse.typ --| @{keyword "+"}) -- |
2359 Scan.repeat1 Parse.const_binding) |
2414 Scan.repeat1 Parse.const_binding) |
2360 >> (fn ((overloaded, x), (y, z)) => |
2415 >> (fn ((overloaded, x), (y, z)) => |
2361 Toplevel.theory (add_record_cmd {overloaded = overloaded} x y z))); |
2416 Toplevel.theory (add_record_cmd {overloaded = overloaded} x y z))); |
2362 |
2417 |
2363 end; |
2418 val opt_modes = |
|
2419 Scan.optional (@{keyword "("} |-- Parse.!!! (Scan.repeat1 Parse.xname --| @{keyword ")"})) [] |
|
2420 |
|
2421 val _ = |
|
2422 Outer_Syntax.command @{command_keyword "print_record"} "print record definiton" |
|
2423 (opt_modes -- Parse.typ >> print_record); |
|
2424 |
|
2425 end |