src/Pure/Syntax/type_ext.ML
author wenzelm
Wed, 06 Apr 2011 21:55:41 +0200
changeset 42262 4821a2a91548
parent 42245 29e3967550d5
child 42263 49b1b8d0782f
permissions -rw-r--r--
moved type syntax translations to syn_trans.ML;
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/type_ext.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
35429
afa8cf9e63d8 authentic syntax for classes and type constructors;
wenzelm
parents: 35262
diff changeset
     4
Utilities for input and output of types.  The concrete syntax of types.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
signature TYPE_EXT0 =
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
     8
sig
42242
39261908e12f moved decode/parse operations to standard_syntax.ML;
wenzelm
parents: 42223
diff changeset
     9
  val decode_position_term: term -> Position.T option
42053
006095137a81 update_name_tr: more precise handling of explicit constraints, including positions;
wenzelm
parents: 42052
diff changeset
    10
  val is_position: term -> bool
42050
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    11
  val strip_positions: term -> term
42052
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    12
  val strip_positions_ast: Ast.ast -> Ast.ast
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    13
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
signature TYPE_EXT =
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    16
sig
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
  include TYPE_EXT0
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36502
diff changeset
    18
  val type_ext: Syn_Ext.syn_ext
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    19
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36502
diff changeset
    21
structure Type_Ext: TYPE_EXT =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
struct
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    23
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    24
(** input utils **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
42050
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    26
(* positions *)
22704
f67607c3e56e added decode_types (from type_infer.ML);
wenzelm
parents: 20854
diff changeset
    27
42242
39261908e12f moved decode/parse operations to standard_syntax.ML;
wenzelm
parents: 42223
diff changeset
    28
fun decode_position_term (Free (x, _)) = Lexicon.decode_position x
39261908e12f moved decode/parse operations to standard_syntax.ML;
wenzelm
parents: 42223
diff changeset
    29
  | decode_position_term _ = NONE;
42131
1d9710ff7209 decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents: 42053
diff changeset
    30
42242
39261908e12f moved decode/parse operations to standard_syntax.ML;
wenzelm
parents: 42223
diff changeset
    31
val is_position = is_some o decode_position_term;
42048
afd11ca8e018 support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents: 39288
diff changeset
    32
42050
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    33
fun strip_positions ((t as Const (c, _)) $ u $ v) =
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    34
      if (c = "_constrain" orelse c = "_constrainAbs") andalso is_position v
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    35
      then strip_positions u
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    36
      else t $ strip_positions u $ strip_positions v
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    37
  | strip_positions (t $ u) = strip_positions t $ strip_positions u
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    38
  | strip_positions (Abs (x, T, t)) = Abs (x, T, strip_positions t)
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    39
  | strip_positions t = t;
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    40
42052
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    41
fun strip_positions_ast (Ast.Appl ((t as Ast.Constant c) :: u :: (v as Ast.Variable x) :: asts)) =
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    42
      if (c = "_constrain" orelse c = "_constrainAbs") andalso is_some (Lexicon.decode_position x)
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    43
      then Ast.mk_appl (strip_positions_ast u) (map strip_positions_ast asts)
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    44
      else Ast.Appl (map strip_positions_ast (t :: u :: v :: asts))
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    45
  | strip_positions_ast (Ast.Appl asts) = Ast.Appl (map strip_positions_ast asts)
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    46
  | strip_positions_ast ast = ast;
34f1d2d81284 statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents: 42050
diff changeset
    47
42050
5a505dfec04e datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents: 42048
diff changeset
    48
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
(** the type syntax **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    52
fun typ c = Type (c, []);
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    53
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    54
val class_nameT = typ "class_name";
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    55
val type_nameT = typ "type_name";
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    56
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    57
val sortT = typ "sort";
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    58
val classesT = typ "classes";
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    59
val typesT = typ "types";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36502
diff changeset
    61
local open Lexicon Syn_Ext in
5690
4b056ee5435c no open;
wenzelm
parents: 3829
diff changeset
    62
35668
69e1740fbfb1 simplified Syntax.basic_syntax (again);
wenzelm
parents: 35433
diff changeset
    63
val type_ext = syn_ext' false (K false)
347
cd41a57221d0 changed translation of type applications according to new grammar;
wenzelm
parents: 330
diff changeset
    64
  [Mfix ("_",           tidT --> typeT,                "", [], max_pri),
239
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    65
   Mfix ("_",           tvarT --> typeT,               "", [], max_pri),
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    66
   Mfix ("_",           type_nameT --> typeT,          "", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    67
   Mfix ("_",           idT --> type_nameT,            "_type_name", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    68
   Mfix ("_",           longidT --> type_nameT,        "_type_name", [], max_pri),
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 258
diff changeset
    69
   Mfix ("_::_",        [tidT, sortT] ---> typeT,      "_ofsort", [max_pri, 0], max_pri),
239
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    70
   Mfix ("_::_",        [tvarT, sortT] ---> typeT,     "_ofsort", [max_pri, 0], max_pri),
14838
b12855d44c97 tuned _dummy_ofsort syntax;
wenzelm
parents: 14255
diff changeset
    71
   Mfix ("'_()::_",     sortT --> typeT,               "_dummy_ofsort", [0], max_pri),
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    72
   Mfix ("_",           class_nameT --> sortT,         "", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    73
   Mfix ("_",           idT --> class_nameT,           "_class_name", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    74
   Mfix ("_",           longidT --> class_nameT,       "_class_name", [], max_pri),
2584
b386951e15e6 improved comments;
wenzelm
parents: 2438
diff changeset
    75
   Mfix ("{}",          sortT,                         "_topsort", [], max_pri),
239
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    76
   Mfix ("{_}",         classesT --> sortT,            "_sort", [], max_pri),
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    77
   Mfix ("_",           class_nameT --> classesT,      "", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    78
   Mfix ("_,_",         [class_nameT, classesT] ---> classesT, "_classes", [], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    79
   Mfix ("_ _",         [typeT, type_nameT] ---> typeT, "_tapp", [max_pri, 0], max_pri),
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 42170
diff changeset
    80
   Mfix ("((1'(_,/ _')) _)", [typeT, typesT, type_nameT] ---> typeT, "_tappl", [], max_pri),
239
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    81
   Mfix ("_",           typeT --> typesT,              "", [], max_pri),
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    82
   Mfix ("_,/ _",       [typeT, typesT] ---> typesT,   "_types", [], max_pri),
35429
afa8cf9e63d8 authentic syntax for classes and type constructors;
wenzelm
parents: 35262
diff changeset
    83
   Mfix ("(_/ => _)",   [typeT, typeT] ---> typeT,     "\\<^type>fun", [1, 0], 0),
624
33b9b5da3e6f made major changes to grammar;
clasohm
parents: 557
diff changeset
    84
   Mfix ("([_]/ => _)", [typesT, typeT] ---> typeT,    "_bracket", [0, 0], 0),
2678
d5fe793293ac added "_" syntax for dummyT;
wenzelm
parents: 2584
diff changeset
    85
   Mfix ("'(_')",       typeT --> typeT,               "", [0], max_pri),
35429
afa8cf9e63d8 authentic syntax for classes and type constructors;
wenzelm
parents: 35262
diff changeset
    86
   Mfix ("'_",          typeT,                         "\\<^type>dummy", [], max_pri)]
35433
73cc288b4f83 "_type_prop" is syntax const -- recovered printing of OFCLASS;
wenzelm
parents: 35429
diff changeset
    87
  ["_type_prop"]
42262
4821a2a91548 moved type syntax translations to syn_trans.ML;
wenzelm
parents: 42245
diff changeset
    88
  ([], [], [], [])
26708
fc2e7d2f763d moved default token translations to proof_context.ML, if all fails the pretty printer falls back on plain output;
wenzelm
parents: 26039
diff changeset
    89
  []
239
08b6e842ec16 minor internal changes;
wenzelm
parents: 18
diff changeset
    90
  ([], []);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
end;
5690
4b056ee5435c no open;
wenzelm
parents: 3829
diff changeset
    93
4b056ee5435c no open;
wenzelm
parents: 3829
diff changeset
    94
end;