1 (* Title: Pure/Thy/term_style.ML
3 Author: Florian Haftmann, TU Muenchen
5 Styles for terms, to use with the "term_style" and "thm_style"
11 val the_style: theory -> string -> (Proof.context -> term -> term)
12 val add_style: string -> (Proof.context -> term -> term) -> theory -> theory
13 val print_styles: theory -> unit
16 structure TermStyle: TERM_STYLE =
21 fun err_dup_style name =
22 error ("Duplicate declaration of antiquote style: " ^ quote name);
24 structure StyleData = TheoryDataFun
26 type T = ((Proof.context -> term -> term) * stamp) Symtab.table;
27 val empty = Symtab.empty;
30 fun merge _ tabs : T = Symtab.merge (eq_snd (op =)) tabs
31 handle Symtab.DUP dup => err_dup_style dup;
34 fun print_styles thy =
35 Pretty.writeln (Pretty.strs ("antiquote styles:" :: Symtab.keys (StyleData.get thy)));
40 fun the_style thy name =
41 (case Symtab.lookup (StyleData.get thy) name of
42 NONE => error ("Unknown antiquote style: " ^ quote name)
43 | SOME (style, _) => style);
45 fun add_style name style thy =
46 StyleData.map (Symtab.update_new (name, (style, stamp ()))) thy
47 handle Symtab.DUP _ => err_dup_style name;
50 (* predefined styles *)
52 fun style_binargs ctxt t =
54 val concl = ObjectLogic.drop_judgment (ProofContext.theory_of ctxt)
55 (Logic.strip_imp_concl t)
57 case concl of (_ $ l $ r) => (l, r)
58 | _ => error ("Binary operator expected in term: " ^ Syntax.string_of_term ctxt concl)
61 fun style_parm_premise i ctxt t =
62 let val prems = Logic.strip_imp_prems t in
63 if i <= length prems then nth prems (i - 1)
64 else error ("Not enough premises for prem" ^ string_of_int i ^
65 " in propositon: " ^ Syntax.string_of_term ctxt t)
68 val _ = Context.add_setup
69 (add_style "lhs" (fst oo style_binargs) #>
70 add_style "rhs" (snd oo style_binargs) #>
71 add_style "prem1" (style_parm_premise 1) #>
72 add_style "prem2" (style_parm_premise 2) #>
73 add_style "prem3" (style_parm_premise 3) #>
74 add_style "prem4" (style_parm_premise 4) #>
75 add_style "prem5" (style_parm_premise 5) #>
76 add_style "prem6" (style_parm_premise 6) #>
77 add_style "prem7" (style_parm_premise 7) #>
78 add_style "prem8" (style_parm_premise 8) #>
79 add_style "prem9" (style_parm_premise 9) #>
80 add_style "prem10" (style_parm_premise 10) #>
81 add_style "prem11" (style_parm_premise 11) #>
82 add_style "prem12" (style_parm_premise 12) #>
83 add_style "prem13" (style_parm_premise 13) #>
84 add_style "prem14" (style_parm_premise 14) #>
85 add_style "prem15" (style_parm_premise 15) #>
86 add_style "prem16" (style_parm_premise 16) #>
87 add_style "prem17" (style_parm_premise 17) #>
88 add_style "prem18" (style_parm_premise 18) #>
89 add_style "prem19" (style_parm_premise 19) #>
90 add_style "concl" (K Logic.strip_imp_concl));