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