src/Pure/Isar/term_style.ML
author haftmann
Tue, 03 May 2005 10:33:31 +0200
changeset 15918 6d6d3fabef02
child 15960 9bd6550dc004
permissions -rw-r--r--
final implementation of antiquotations styles
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15918
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Isar/term_style.ML
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     2
    ID:         $Id$
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     4
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     5
Styles for terms, to use with the "term_style" and "thm_style" antiquotations
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     6
*)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     7
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     8
signature STYLE =
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
     9
sig
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    10
  val get_style: theory -> string -> (Term.term -> Term.term)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    11
  val put_style: string -> (Term.term -> Term.term) -> theory -> theory
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    12
end;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    13
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    14
structure Style: STYLE =
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    15
struct
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    16
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    17
(* exception *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    18
exception STYLE of string;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    19
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    20
(* style data *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    21
structure StyleArgs =
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    22
struct
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    23
  val name = "Isar/style";
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    24
  type T = (string * (Term.term -> Term.term)) list;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    25
  val empty = [];
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    26
  val copy = I;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    27
  val prep_ext = I;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    28
  fun merge (a1, a2) = Library.foldl Library.overwrite (a1, a2);
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    29
    (* piecewise update of a1 by a2 *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    30
  fun print _ _ = raise (STYLE "cannot print style (not implemented)");
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    31
end;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    32
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    33
structure StyleData = TheoryDataFun(StyleArgs);
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    34
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    35
(* accessors *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    36
fun get_style thy name =
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    37
  case Library.assoc_string ((StyleData.get thy), name)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    38
    of NONE => raise (STYLE ("no style named " ^ name))
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    39
     | SOME style => style
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    40
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    41
fun put_style name style thy =
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    42
  StyleData.put (Library.overwrite ((StyleData.get thy), (name, style))) thy;
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    43
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    44
(* predefined styles *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    45
fun style_lhs (Const ("==", _) $ t $ _) = t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    46
  | style_lhs (Const ("Trueprop", _) $ t) = style_lhs t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    47
  | style_lhs (Const ("==>", _) $ _ $ t) = style_lhs t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    48
  | style_lhs (_ $ t $ _) = t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    49
  | style_lhs _ = error ("Binary operator expected")
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    50
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    51
fun style_rhs (Const ("==", _) $ _ $ t) = t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    52
  | style_rhs (Const ("Trueprop", _) $ t) = style_rhs t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    53
  | style_rhs (Const ("==>", _) $ _ $ t) = style_rhs t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    54
  | style_rhs (_ $ _ $ t) = t
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    55
  | style_rhs _ = error ("Binary operator expected")
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    56
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    57
(* initialization *)
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    58
val _ = Context.add_setup [StyleData.init,
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    59
  put_style "lhs" style_lhs,
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    60
  put_style "rhs" style_rhs,
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    61
  put_style "conclusion" Logic.strip_imp_concl
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    62
];
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    63
6d6d3fabef02 final implementation of antiquotations styles
haftmann
parents:
diff changeset
    64
end;