author | wenzelm |
Sat, 17 May 2008 23:37:07 +0200 | |
changeset 26934 | c1ae80a58341 |
parent 26463 | 9283b4185fdf |
child 29606 | fedb8be05f24 |
permissions | -rw-r--r-- |
22107 | 1 |
(* Title: Pure/Thy/term_style.ML |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
||
5 |
Styles for terms, to use with the "term_style" and "thm_style" |
|
6 |
antiquotations. |
|
7 |
*) |
|
8 |
||
9 |
signature TERM_STYLE = |
|
10 |
sig |
|
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 |
|
14 |
end; |
|
15 |
||
16 |
structure TermStyle: TERM_STYLE = |
|
17 |
struct |
|
18 |
||
19 |
(* style data *) |
|
20 |
||
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23577
diff
changeset
|
21 |
fun err_dup_style name = |
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23577
diff
changeset
|
22 |
error ("Duplicate declaration of antiquote style: " ^ quote name); |
22107 | 23 |
|
24 |
structure StyleData = TheoryDataFun |
|
22846 | 25 |
( |
22107 | 26 |
type T = ((Proof.context -> term -> term) * stamp) Symtab.table; |
27 |
val empty = Symtab.empty; |
|
28 |
val copy = I; |
|
29 |
val extend = I; |
|
23577 | 30 |
fun merge _ tabs : T = Symtab.merge (eq_snd (op =)) tabs |
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23577
diff
changeset
|
31 |
handle Symtab.DUP dup => err_dup_style dup; |
22846 | 32 |
); |
22107 | 33 |
|
22846 | 34 |
fun print_styles thy = |
35 |
Pretty.writeln (Pretty.strs ("antiquote styles:" :: Symtab.keys (StyleData.get thy))); |
|
22107 | 36 |
|
37 |
||
38 |
(* accessors *) |
|
39 |
||
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); |
|
44 |
||
45 |
fun add_style name style thy = |
|
46 |
StyleData.map (Symtab.update_new (name, (style, stamp ()))) thy |
|
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23577
diff
changeset
|
47 |
handle Symtab.DUP _ => err_dup_style name; |
22107 | 48 |
|
49 |
||
50 |
(* predefined styles *) |
|
51 |
||
52 |
fun style_binargs ctxt t = |
|
53 |
let |
|
54 |
val concl = ObjectLogic.drop_judgment (ProofContext.theory_of ctxt) |
|
55 |
(Logic.strip_imp_concl t) |
|
56 |
in |
|
57 |
case concl of (_ $ l $ r) => (l, r) |
|
24920 | 58 |
| _ => error ("Binary operator expected in term: " ^ Syntax.string_of_term ctxt concl) |
22107 | 59 |
end; |
60 |
||
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 ^ |
|
24920 | 65 |
" in propositon: " ^ Syntax.string_of_term ctxt t) |
22107 | 66 |
end; |
67 |
||
26463 | 68 |
val _ = Context.>> (Context.map_theory |
22107 | 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) #> |
|
26463 | 90 |
add_style "concl" (K Logic.strip_imp_concl))); |
22107 | 91 |
|
92 |
end; |