src/Pure/Syntax/sextension.ML
author nipkow
Thu, 11 Nov 1993 13:24:47 +0100
changeset 113 1e669b5a75f9
parent 48 bc48a71464b0
child 165 793be9f1e88e
permissions -rw-r--r--
changed formatting for application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     1
(*  Title:      Pure/Syntax/sextension.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     5
Syntax extensions (external interface): mixfix declarations, syntax rules,
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     6
infixes, binders and the Pure syntax.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
TODO:
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     9
  move ast_to_term (?)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
infix |-> <-| <->;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
signature SEXTENSION0 =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
  structure Ast: AST
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
  local open Ast in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
    datatype mixfix =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
      Mixfix of string * string * string * int list * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
      Delimfix of string * string * string |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
      Infixl of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
      Infixr of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
      Binder of string * string * string * int * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
      TInfixl of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
      TInfixr of string * string * int
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
    datatype xrule =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
      op |-> of (string * string) * (string * string) |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
      op <-| of (string * string) * (string * string) |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
      op <-> of (string * string) * (string * string)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
    datatype sext =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
      Sext of {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
        mixfix: mixfix list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
        parse_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
        print_translation: (string * (term list -> term)) list} |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
      NewSext of {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
        mixfix: mixfix list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
        xrules: xrule list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
        parse_ast_translation: (string * (ast list -> ast)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
        parse_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
        print_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
        print_ast_translation: (string * (ast list -> ast)) list}
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
    val eta_contract: bool ref
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
    val mk_binder_tr: string * string -> string * (term list -> term)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
    val mk_binder_tr': string * string -> string * (term list -> term)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
    val dependent_tr': string * string -> term list -> term
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
    val max_pri: int
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
  end
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
signature SEXTENSION1 =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
  include SEXTENSION0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
  val empty_sext: sext
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
  val simple_sext: mixfix list -> sext
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
  val constants: sext -> (string list * string) list
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
  val pure_sext: sext
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
  val syntax_types: string list
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
  val constrainAbsC: string
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
signature SEXTENSION =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
  include SEXTENSION1
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
  structure Extension: EXTENSION
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
  sharing Extension.XGram.Ast = Ast
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
  local open Extension Ast in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
    val xrules_of: sext -> xrule list
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
    val abs_tr': term -> term
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
    val appl_ast_tr': ast * ast list -> ast
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
    val ext_of_sext: string list -> string list -> (string -> typ) -> sext -> ext
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
    val ast_to_term: (string -> (term list -> term) option) -> ast -> term
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
    val constrainIdtC: string
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
    val apropC: string
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
  end
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    77
functor SExtensionFun(structure TypeExt: TYPE_EXT and Lexicon: LEXICON): SEXTENSION =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
structure Extension = TypeExt.Extension;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
structure Ast = Extension.XGram.Ast;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
    82
open Lexicon Extension Extension.XGram Ast;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
(** datatype sext **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
datatype mixfix =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
  Mixfix of string * string * string * int list * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
  Delimfix of string * string * string |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
  Infixl of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
  Infixr of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
  Binder of string * string * string * int * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
  TInfixl of string * string * int |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
  TInfixr of string * string * int;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
datatype xrule =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
  op |-> of (string * string) * (string * string) |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
  op <-| of (string * string) * (string * string) |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
  op <-> of (string * string) * (string * string);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
datatype sext =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
  Sext of {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
    mixfix: mixfix list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
    parse_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
    print_translation: (string * (term list -> term)) list} |
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
  NewSext of {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
    mixfix: mixfix list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
    xrules: xrule list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
    parse_ast_translation: (string * (ast list -> ast)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
    parse_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
    print_translation: (string * (term list -> term)) list,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
    print_ast_translation: (string * (ast list -> ast)) list};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
(* simple_sext *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
fun simple_sext mixfix =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
  Sext {mixfix = mixfix, parse_translation = [], print_translation = []};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   119
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
(* empty_sext *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   123
val empty_sext = simple_sext [];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
(* sext_components *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
fun sext_components (Sext {mixfix, parse_translation, print_translation}) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
      {mixfix = mixfix,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
        xrules = [],
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
        parse_ast_translation = [],
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   132
        parse_translation = parse_translation,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
        print_translation = print_translation,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
        print_ast_translation = []}
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
  | sext_components (NewSext cmps) = cmps;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   137
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
(* mixfix_of *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   140
fun mixfix_of (Sext {mixfix, ...}) = mixfix
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   141
  | mixfix_of (NewSext {mixfix, ...}) = mixfix;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   143
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   144
(* xrules_of *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   146
fun xrules_of (Sext _) = []
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   147
  | xrules_of (NewSext {xrules, ...}) = xrules;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   148
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   149
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   150
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   151
(** parse (ast) translations **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   152
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   153
(* application *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   154
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   155
fun appl_ast_tr (*"_appl"*) [f, args] = Appl (f :: unfold_ast "_args" args)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   156
  | appl_ast_tr (*"_appl"*) asts = raise_ast "appl_ast_tr" asts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   157
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   158
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   159
(* abstraction *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
fun idtyp_ast_tr (*"_idtyp"*) [x, ty] = Appl [Constant constrainC, x, ty]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
  | idtyp_ast_tr (*"_idtyp"*) asts = raise_ast "idtyp_ast_tr" asts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
fun lambda_ast_tr (*"_lambda"*) [idts, body] =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   165
      fold_ast_p "_abs" (unfold_ast "_idts" idts, body)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
  | lambda_ast_tr (*"_lambda"*) asts = raise_ast "lambda_ast_tr" asts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   167
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   168
fun abs_tr (*"_abs"*) [Free (x, T), body] = absfree (x, T, body)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   169
  | abs_tr (*"_abs"*) (ts as [Const (c, _) $ Free (x, T) $ tT, body]) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   170
      if c = constrainC then
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   171
        Const ("_constrainAbs", dummyT) $ absfree (x, T, body) $ tT
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   172
      else raise_term "abs_tr" ts
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   173
  | abs_tr (*"_abs"*) ts = raise_term "abs_tr" ts;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   174
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   176
(* nondependent abstraction *)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   177
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   178
fun k_tr (*"_K"*) [t] = Abs ("x", dummyT, incr_boundvars 1 t)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   179
  | k_tr (*"_K"*) ts = raise_term "k_tr" ts;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   180
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   181
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   182
(* binder *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   184
fun mk_binder_tr (sy, name) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
  let
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
    val const = Const (name, dummyT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   187
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   188
    fun tr (Free (x, T), t) = const $ absfree (x, T, t)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   189
      | tr (Const ("_idts", _) $ idt $ idts, t) = tr (idt, tr (idts, t))
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   190
      | tr (t1 as Const (c, _) $ Free (x, T) $ tT, t) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   191
          if c = constrainC then
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   192
            const $ (Const ("_constrainAbs", dummyT) $ absfree (x, T, t) $ tT)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   193
          else raise_term "binder_tr" [t1, t]
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   194
      | tr (t1, t2) = raise_term "binder_tr" [t1, t2];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   195
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   196
    fun binder_tr (*sy*) [idts, body] = tr (idts, body)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   197
      | binder_tr (*sy*) ts = raise_term "binder_tr" ts;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   198
  in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
    (sy, binder_tr)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   202
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
(* atomic props *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   204
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   205
fun aprop_tr (*"_aprop"*) [t] =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   206
      Const (constrainC, dummyT) $ t $ Free ("prop", dummyT)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   207
  | aprop_tr (*"_aprop"*) ts = raise_term "aprop_tr" ts;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   208
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   209
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
(* meta implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   211
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
fun bigimpl_ast_tr (*"_bigimpl"*) [asms, concl] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   213
      fold_ast_p "==>" (unfold_ast "_asms" asms, concl)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   214
  | bigimpl_ast_tr (*"_bigimpl"*) asts = raise_ast "bigimpl_ast_tr" asts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   215
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   217
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   218
(** print (ast) translations **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   219
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   220
(* application *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   222
fun appl_ast_tr' (f, []) = raise_ast "appl_ast_tr'" [f]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
  | appl_ast_tr' (f, args) = Appl [Constant "_appl", f, fold_ast "_args" args];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   225
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   226
(* abstraction *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   227
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   228
fun strip_abss vars_of body_of tm =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   229
  let
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   230
    fun free (x, _) = Free (x, dummyT);
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   231
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   232
    val vars = vars_of tm;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   233
    val body = body_of tm;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   234
    val rev_new_vars = rename_wrt_term body vars;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   235
  in
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   236
    (map Free (rev rev_new_vars), subst_bounds (map free rev_new_vars, body))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   237
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   238
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   239
(*do (partial) eta-contraction before printing*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   240
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   241
val eta_contract = ref false;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   242
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   243
fun eta_contr tm =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   244
  let
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   245
    fun eta_abs (Abs (a, T, t)) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   246
          (case eta_abs t of
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   247
            t' as f $ u =>
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   248
              (case eta_abs u of
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   249
                Bound 0 =>
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   250
                  if not (0 mem loose_bnos f) then incr_boundvars ~1 f
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   251
                  else Abs (a, T, t')
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   252
              | _ => Abs (a, T, t'))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   253
          | t' => Abs (a, T, t'))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   254
      | eta_abs t = t;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   255
  in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   256
    if ! eta_contract then eta_abs tm else tm
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   257
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   258
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   259
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   260
fun abs_tr' tm =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   261
  foldr (fn (x, t) => Const ("_abs", dummyT) $ x $ t)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   262
    (strip_abss strip_abs_vars strip_abs_body (eta_contr tm));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   263
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   264
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   265
fun abs_ast_tr' (*"_abs"*) asts =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   266
  (case unfold_ast_p "_abs" (Appl (Constant "_abs" :: asts)) of
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   267
    ([], _) => raise_ast "abs_ast_tr'" asts
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   268
  | (xs, body) => Appl [Constant "_lambda", fold_ast "_idts" xs, body]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   269
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   270
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   271
(* binder *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   272
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   273
fun mk_binder_tr' (name, sy) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   274
  let
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   275
    fun mk_idts [] = raise Match    (*abort translation*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   276
      | mk_idts [idt] = idt
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   277
      | mk_idts (idt :: idts) = Const ("_idts", dummyT) $ idt $ mk_idts idts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   278
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   279
    fun tr' t =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   280
      let
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   281
        val (xs, bd) = strip_abss (strip_qnt_vars name) (strip_qnt_body name) t;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   282
      in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   283
        Const (sy, dummyT) $ mk_idts xs $ bd
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   284
      end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   285
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   286
    fun binder_tr' (*name*) (t :: ts) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   287
          list_comb (tr' (Const (name, dummyT) $ t), ts)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   288
      | binder_tr' (*name*) [] = raise Match;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   289
  in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   290
    (name, binder_tr')
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   291
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   292
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   293
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   294
(* idts *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   295
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   296
fun idts_ast_tr' (*"_idts"*) [Appl [Constant c, x, ty], xs] =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   297
      if c = constrainC then
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   298
        Appl [Constant "_idts", Appl [Constant "_idtyp", x, ty], xs]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   299
      else raise Match
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   300
  | idts_ast_tr' (*"_idts"*) _ = raise Match;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   301
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   302
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   303
(* meta implication *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   304
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   305
fun impl_ast_tr' (*"==>"*) asts =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   306
  (case unfold_ast_p "==>" (Appl (Constant "==>" :: asts)) of
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   307
    (asms as _ :: _ :: _, concl)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   308
      => Appl [Constant "_bigimpl", fold_ast "_asms" asms, concl]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   309
  | _ => raise Match);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   310
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   311
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   312
(* dependent / nondependent quantifiers *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   313
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   314
fun dependent_tr' (q, r) (A :: Abs (x, T, B) :: ts) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   315
      if 0 mem (loose_bnos B) then
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   316
        let val (x', B') = variant_abs (x, dummyT, B);
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   317
        in list_comb (Const (q, dummyT) $ Free (x', T) $ A $ B', ts) end
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   318
      else list_comb (Const (r, dummyT) $ A $ B, ts)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   319
  | dependent_tr' _ _ = raise Match;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   320
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   321
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   322
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   323
(** ext_of_sext **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   324
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   325
fun strip_esc str =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   326
  let
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   327
    fun strip ("'" :: c :: cs) = c :: strip cs
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   328
      | strip ["'"] = []
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   329
      | strip (c :: cs) = c :: strip cs
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   330
      | strip [] = [];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   331
  in
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   332
    implode (strip (explode str))
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   333
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   334
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   335
fun infix_name sy = "op " ^ strip_esc sy;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   336
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   337
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   338
fun ext_of_sext roots xconsts read_typ sext =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   339
  let
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   340
    val {mixfix, parse_ast_translation, parse_translation, print_translation,
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   341
      print_ast_translation, ...} = sext_components sext;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   342
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   343
    val tinfixT = [typeT, typeT] ---> typeT;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   344
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   345
    fun binder (Binder (sy, _, name, _, _)) = Some (sy, name)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   346
      | binder _ = None;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   347
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   348
    fun binder_typ ty =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   349
      (case read_typ ty of
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   350
        Type ("fun", [Type ("fun", [_, T2]), T3]) =>
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   351
          [Type ("idts", []), T2] ---> T3
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   352
      | _ => error ("Illegal binder type " ^ quote ty));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   353
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   354
    fun mk_infix sy T c p1 p2 p3 =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   355
      [Mfix ("op " ^ sy, T, c, [], max_pri),
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   356
       Mfix ("(_ " ^ sy ^ "/ _)", T, c, [p1, p2], p3)];
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   357
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   358
    fun mfix_of (Mixfix (sy, ty, c, ps, p)) = [Mfix (sy, read_typ ty, c, ps, p)]
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   359
      | mfix_of (Delimfix (sy, ty, c)) = [Mfix (sy, read_typ ty, c, [], max_pri)]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   360
      | mfix_of (Infixl (sy, ty, p)) =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   361
          mk_infix sy (read_typ ty) (infix_name sy) p (p + 1) p
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   362
      | mfix_of (Infixr (sy, ty, p)) =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   363
          mk_infix sy (read_typ ty) (infix_name sy) (p + 1) p p
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   364
      | mfix_of (Binder (sy, ty, _, p, q)) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   365
          [Mfix ("(3" ^ sy ^ "_./ _)", binder_typ ty, sy, [0, p], q)]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   366
      | mfix_of (TInfixl (s, c, p)) =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   367
          [Mfix ("(_ " ^ s ^ "/ _)", tinfixT, c, [p, p + 1], p)]
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   368
      | mfix_of (TInfixr (s, c, p)) =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   369
          [Mfix ("(_ " ^ s ^ "/ _)", tinfixT, c, [p + 1, p], p)];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   370
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   371
    val mfix = flat (map mfix_of mixfix);
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   372
    val binders = mapfilter binder mixfix;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   373
    val bparses = map mk_binder_tr binders;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   374
    val bprints = map (mk_binder_tr' o (fn (x, y) => (y, x))) binders;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   375
  in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   376
    Ext {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   377
      roots = roots, mfix = mfix,
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   378
      extra_consts = distinct (filter is_xid xconsts),
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   379
      parse_ast_translation = parse_ast_translation,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   380
      parse_translation = bparses @ parse_translation,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   381
      print_translation = bprints @ print_translation,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   382
      print_ast_translation = print_ast_translation}
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   383
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   384
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   385
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   386
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   387
(** constants **)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   388
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   389
fun constants sext =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   390
  let
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   391
    fun consts (Delimfix (_, ty, c)) = ([c], ty)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   392
      | consts (Mixfix (_, ty, c, _, _)) = ([c], ty)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   393
      | consts (Infixl (c, ty, _)) = ([infix_name c], ty)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   394
      | consts (Infixr (c, ty, _)) = ([infix_name c], ty)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   395
      | consts (Binder (_, ty, c, _, _)) = ([c], ty)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   396
      | consts _ = ([""], "");    (*is filtered out below*)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   397
  in
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   398
    distinct (filter_out (fn (l, _) => l = [""]) (map consts (mixfix_of sext)))
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   399
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   400
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   401
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   402
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   403
(** ast_to_term **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   404
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   405
fun ast_to_term trf ast =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   406
  let
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   407
    fun trans a args =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   408
      (case trf a of
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   409
        None => list_comb (Const (a, dummyT), args)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   410
      | Some f => f args handle exn
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   411
          => (writeln ("Error in parse translation for " ^ quote a); raise exn));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   412
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   413
    fun term_of (Constant a) = trans a []
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   414
      | term_of (Variable x) = scan_var x
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   415
      | term_of (Appl (Constant a :: (asts as _ :: _))) =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   416
          trans a (map term_of asts)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   417
      | term_of (Appl (ast :: (asts as _ :: _))) =
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   418
          list_comb (term_of ast, map term_of asts)
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   419
      | term_of (ast as Appl _) = raise_ast "ast_to_term: malformed ast" [ast];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   420
  in
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   421
    term_of ast
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   422
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   423
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   424
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   425
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   426
(** the Pure syntax **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   427
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   428
val pure_sext =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   429
  NewSext {
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   430
    mixfix = [
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   431
      Mixfix   ("(3%_./ _)",  "[idts, 'a] => ('b => 'a)",      "_lambda", [0], 0),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   432
      Delimfix ("_",          "'a => " ^ args,                 ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   433
      Delimfix ("_,/ _",      "['a, " ^ args ^ "] => " ^ args, "_args"),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   434
      Delimfix ("_",          "id => idt",                     ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   435
      Mixfix   ("_::_",       "[id, type] => idt",             "_idtyp", [0, 0], 0),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   436
      Delimfix ("'(_')",      "idt => idt",                    ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   437
      Delimfix ("_",          "idt => idts",                   ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   438
      Mixfix   ("_/ _",       "[idt, idts] => idts",           "_idts", [1, 0], 0),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   439
      Delimfix ("_",          "id => aprop",                   ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   440
      Delimfix ("_",          "var => aprop",                  ""),
113
1e669b5a75f9 changed formatting for application
nipkow
parents: 48
diff changeset
   441
      Mixfix   ("(1_/(1'(_')))", "[('b => 'a), " ^ args ^ "] => aprop", applC, [max_pri, 0], 0),
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   442
      Delimfix ("PROP _",     "aprop => prop",                 "_aprop"),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   443
      Delimfix ("_",          "prop => asms",                  ""),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   444
      Delimfix ("_;/ _",      "[prop, asms] => asms",          "_asms"),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   445
      Mixfix   ("((3[| _ |]) ==>/ _)", "[asms, prop] => prop", "_bigimpl", [0, 1], 1),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   446
      Mixfix   ("(_ ==/ _)",  "['a::{}, 'a] => prop",          "==", [3, 2], 2),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   447
      Mixfix   ("(_ =?=/ _)", "['a::{}, 'a] => prop",          "=?=", [3, 2], 2),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   448
      Mixfix   ("(_ ==>/ _)", "[prop, prop] => prop",          "==>", [2, 1], 1),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   449
      Binder   ("!!",         "('a::logic => prop) => prop",   "all", 0, 0)],
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   450
    xrules = [],
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   451
    parse_ast_translation =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   452
      [(applC, appl_ast_tr), ("_lambda", lambda_ast_tr), ("_idtyp", idtyp_ast_tr),
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   453
        ("_bigimpl", bigimpl_ast_tr)],
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   454
    parse_translation = [("_abs", abs_tr), ("_K", k_tr), ("_aprop", aprop_tr)],
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   455
    print_translation = [],
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   456
    print_ast_translation = [("_abs", abs_ast_tr'), ("_idts", idts_ast_tr'),
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   457
      ("==>", impl_ast_tr')]};
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   458
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   459
val syntax_types = [id, var, tfree, tvar, logic, "type", "types", "sort",
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   460
  "classes", args, "idt", "idts", "aprop", "asms"];
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   461
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   462
val constrainIdtC = "_idtyp";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   463
val constrainAbsC = "_constrainAbs";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   464
val apropC = "_aprop";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   465
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   466
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   467
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   468