15918
|
1 |
(* Title: Pure/Isar/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" antiquotations
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature STYLE =
|
|
9 |
sig
|
|
10 |
val get_style: theory -> string -> (Term.term -> Term.term)
|
|
11 |
val put_style: string -> (Term.term -> Term.term) -> theory -> theory
|
|
12 |
end;
|
|
13 |
|
|
14 |
structure Style: STYLE =
|
|
15 |
struct
|
|
16 |
|
|
17 |
(* exception *)
|
|
18 |
exception STYLE of string;
|
|
19 |
|
|
20 |
(* style data *)
|
|
21 |
structure StyleArgs =
|
|
22 |
struct
|
|
23 |
val name = "Isar/style";
|
|
24 |
type T = (string * (Term.term -> Term.term)) list;
|
|
25 |
val empty = [];
|
|
26 |
val copy = I;
|
|
27 |
val prep_ext = I;
|
|
28 |
fun merge (a1, a2) = Library.foldl Library.overwrite (a1, a2);
|
|
29 |
(* piecewise update of a1 by a2 *)
|
|
30 |
fun print _ _ = raise (STYLE "cannot print style (not implemented)");
|
|
31 |
end;
|
|
32 |
|
|
33 |
structure StyleData = TheoryDataFun(StyleArgs);
|
|
34 |
|
|
35 |
(* accessors *)
|
|
36 |
fun get_style thy name =
|
|
37 |
case Library.assoc_string ((StyleData.get thy), name)
|
|
38 |
of NONE => raise (STYLE ("no style named " ^ name))
|
|
39 |
| SOME style => style
|
|
40 |
|
|
41 |
fun put_style name style thy =
|
|
42 |
StyleData.put (Library.overwrite ((StyleData.get thy), (name, style))) thy;
|
|
43 |
|
|
44 |
(* predefined styles *)
|
|
45 |
fun style_lhs (Const ("==", _) $ t $ _) = t
|
|
46 |
| style_lhs (Const ("Trueprop", _) $ t) = style_lhs t
|
|
47 |
| style_lhs (Const ("==>", _) $ _ $ t) = style_lhs t
|
|
48 |
| style_lhs (_ $ t $ _) = t
|
|
49 |
| style_lhs _ = error ("Binary operator expected")
|
|
50 |
|
|
51 |
fun style_rhs (Const ("==", _) $ _ $ t) = t
|
|
52 |
| style_rhs (Const ("Trueprop", _) $ t) = style_rhs t
|
|
53 |
| style_rhs (Const ("==>", _) $ _ $ t) = style_rhs t
|
|
54 |
| style_rhs (_ $ _ $ t) = t
|
|
55 |
| style_rhs _ = error ("Binary operator expected")
|
|
56 |
|
|
57 |
(* initialization *)
|
|
58 |
val _ = Context.add_setup [StyleData.init,
|
|
59 |
put_style "lhs" style_lhs,
|
|
60 |
put_style "rhs" style_rhs,
|
|
61 |
put_style "conclusion" Logic.strip_imp_concl
|
|
62 |
];
|
|
63 |
|
|
64 |
end;
|