src/Pure/Syntax/mixfix.ML
author wenzelm
Wed, 30 Mar 2016 14:59:12 +0200
changeset 62760 aabcc727aa2d
parent 62759 d16b2ec535ba
child 62761 5c672b22dcc2
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Syntax/mixfix.ML
551
4c139c37dbaf minor cleanings;
wenzelm
parents: 472
diff changeset
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
     3
18719
dca3ae4f6dd6 moved pure syntax to Syntax/syntax.ML and pure_thy.ML;
wenzelm
parents: 18673
diff changeset
     4
Mixfix declarations, infixes, binders.
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
     5
*)
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
     6
42287
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
     7
signature BASIC_MIXFIX =
2199
bcb360f80dac added Infixl/rName: specify infix name independently from syntax;
wenzelm
parents: 1952
diff changeset
     8
sig
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
     9
  datatype mixfix =
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    10
    NoSyn |
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    11
    Mixfix of Input.source * int list * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    12
    Delimfix of Input.source * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    13
    Infix of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    14
    Infixl of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    15
    Infixr of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    16
    Binder of Input.source * int * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    17
    Structure of Position.range
2199
bcb360f80dac added Infixl/rName: specify infix name independently from syntax;
wenzelm
parents: 1952
diff changeset
    18
end;
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    19
42287
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
    20
signature MIXFIX =
2199
bcb360f80dac added Infixl/rName: specify infix name independently from syntax;
wenzelm
parents: 1952
diff changeset
    21
sig
42287
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
    22
  include BASIC_MIXFIX
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    23
  val is_empty: mixfix -> bool
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    24
  val equal: mixfix * mixfix -> bool
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    25
  val range_of: mixfix -> Position.range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    26
  val pos_of: mixfix -> Position.T
62759
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    27
  val reset_pos: mixfix -> mixfix
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    28
  val pretty_mixfix: mixfix -> Pretty.T
4823
588538fb9308 added no_syn;
wenzelm
parents: 4697
diff changeset
    29
  val mixfix_args: mixfix -> int
22702
372da033ed93 added mixfixT (from type_infer.ML);
wenzelm
parents: 21805
diff changeset
    30
  val mixfixT: mixfix -> typ
35412
b8dead547d9e more uniform treatment of syntax for types vs. consts;
wenzelm
parents: 35390
diff changeset
    31
  val make_type: int -> typ
42287
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
    32
  val binder_name: string -> string
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42287
diff changeset
    33
  val syn_ext_types: (string * typ * mixfix) list -> Syntax_Ext.syn_ext
59841
2551ac44150e tuned signature;
wenzelm
parents: 55763
diff changeset
    34
  val syn_ext_consts: string list -> (string * typ * mixfix) list -> Syntax_Ext.syn_ext
2199
bcb360f80dac added Infixl/rName: specify infix name independently from syntax;
wenzelm
parents: 1952
diff changeset
    35
end;
bcb360f80dac added Infixl/rName: specify infix name independently from syntax;
wenzelm
parents: 1952
diff changeset
    36
15751
65e4790c7914 identify binder translations only once (admits remove);
wenzelm
parents: 15570
diff changeset
    37
structure Mixfix: MIXFIX =
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    38
struct
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    39
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    40
(** mixfix declarations **)
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    41
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    42
datatype mixfix =
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    43
  NoSyn |
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    44
  Mixfix of Input.source * int list * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    45
  Delimfix of Input.source * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    46
  Infix of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    47
  Infixl of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    48
  Infixr of Input.source * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    49
  Binder of Input.source * int * int * Position.range |
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    50
  Structure of Position.range;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    51
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    52
fun is_empty NoSyn = true
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    53
  | is_empty _ = false;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    54
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    55
fun equal (NoSyn, NoSyn) = true
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    56
  | equal (Mixfix (sy, ps, p, _), Mixfix (sy', ps', p', _)) =
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    57
      Input.equal_content (sy, sy') andalso ps = ps' andalso p = p'
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    58
  | equal (Delimfix (sy, _), Delimfix (sy', _)) = Input.equal_content (sy, sy')
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    59
  | equal (Infix (sy, p, _), Infix (sy', p', _)) = Input.equal_content (sy, sy') andalso p = p'
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    60
  | equal (Infixl (sy, p, _), Infixl (sy', p', _)) = Input.equal_content (sy, sy') andalso p = p'
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    61
  | equal (Infixr (sy, p, _), Infixr (sy', p', _)) = Input.equal_content (sy, sy') andalso p = p'
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    62
  | equal (Binder (sy, p, q, _), Binder (sy', p', q', _)) =
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    63
      Input.equal_content (sy, sy') andalso p = p' andalso q = q'
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    64
  | equal (Structure _, Structure _) = true
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    65
  | equal _ = false;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    66
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    67
fun range_of NoSyn = Position.no_range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    68
  | range_of (Mixfix (_, _, _, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    69
  | range_of (Delimfix (_, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    70
  | range_of (Infix (_, _, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    71
  | range_of (Infixl (_, _, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    72
  | range_of (Infixr (_, _, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    73
  | range_of (Binder (_, _, _, range)) = range
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    74
  | range_of (Structure range) = range;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    75
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    76
val pos_of = Position.set_range o range_of;
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    77
62759
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    78
fun reset_pos NoSyn = NoSyn
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    79
  | reset_pos (Mixfix (sy, ps, p, _)) = Mixfix (Input.reset_pos sy, ps, p, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    80
  | reset_pos (Delimfix (sy, _)) = Delimfix (Input.reset_pos sy, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    81
  | reset_pos (Infix (sy, p, _)) = Infix (Input.reset_pos sy, p, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    82
  | reset_pos (Infixl (sy, p, _)) = Infixl (Input.reset_pos sy, p, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    83
  | reset_pos (Infixr (sy, p, _)) = Infixr (Input.reset_pos sy, p, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    84
  | reset_pos (Binder (sy, p, q, _)) = Binder (Input.reset_pos sy, p, q, Position.no_range)
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    85
  | reset_pos (Structure _) = Structure Position.no_range;
d16b2ec535ba more operations;
wenzelm
parents: 62753
diff changeset
    86
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
    87
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    88
(* pretty_mixfix *)
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    89
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    90
local
11920
6833cadb4062 added string_of_mixfix;
wenzelm
parents: 11651
diff changeset
    91
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
    92
val quoted = Pretty.quote o Pretty.str o Input.source_content;
55763
4b3907cb5654 tuned signature;
wenzelm
parents: 52143
diff changeset
    93
val keyword = Pretty.keyword2;
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    94
val parens = Pretty.enclose "(" ")";
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    95
val brackets = Pretty.enclose "[" "]";
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    96
val int = Pretty.str o string_of_int;
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    97
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
    98
in
11920
6833cadb4062 added string_of_mixfix;
wenzelm
parents: 11651
diff changeset
    99
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
   100
fun pretty_mixfix NoSyn = Pretty.str ""
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   101
  | pretty_mixfix (Mixfix (s, ps, p, _)) =
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
   102
      parens (Pretty.breaks [quoted s, brackets (Pretty.commas (map int ps)), int p])
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   103
  | pretty_mixfix (Delimfix (s, _)) = parens [quoted s]
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   104
  | pretty_mixfix (Infix (s, p, _)) = parens (Pretty.breaks [keyword "infix", quoted s, int p])
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   105
  | pretty_mixfix (Infixl (s, p, _)) = parens (Pretty.breaks [keyword "infixl", quoted s, int p])
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   106
  | pretty_mixfix (Infixr (s, p, _)) = parens (Pretty.breaks [keyword "infixl", quoted s, int p])
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   107
  | pretty_mixfix (Binder (s, p1, p2, _)) =
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
   108
      parens (Pretty.breaks [keyword "binder", quoted s, brackets [int p1], int p2])
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   109
  | pretty_mixfix (Structure _) = parens [keyword "structure"];
19271
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
   110
967e6c2578f2 turned string_of_mixfix into pretty_mixfix;
wenzelm
parents: 19020
diff changeset
   111
end;
11920
6833cadb4062 added string_of_mixfix;
wenzelm
parents: 11651
diff changeset
   112
6833cadb4062 added string_of_mixfix;
wenzelm
parents: 11651
diff changeset
   113
12531
adc39b100e9a improved mixfix_args;
wenzelm
parents: 12512
diff changeset
   114
(* syntax specifications *)
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   115
4053
c88d0d5ae806 added mixfix_args;
wenzelm
parents: 3829
diff changeset
   116
fun mixfix_args NoSyn = 0
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   117
  | mixfix_args (Mixfix (sy, _, _, _)) = Syntax_Ext.mixfix_args sy
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   118
  | mixfix_args (Delimfix (sy, _)) = Syntax_Ext.mixfix_args sy
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   119
  | mixfix_args (Infix (sy, _, _)) = 2 + Syntax_Ext.mixfix_args sy
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   120
  | mixfix_args (Infixl (sy, _, _)) = 2 + Syntax_Ext.mixfix_args sy
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   121
  | mixfix_args (Infixr (sy, _, _)) = 2 + Syntax_Ext.mixfix_args sy
18673
fad60fe1565c mixfix: added Structure;
wenzelm
parents: 18565
diff changeset
   122
  | mixfix_args (Binder _) = 1
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   123
  | mixfix_args (Structure _) = 0;
4053
c88d0d5ae806 added mixfix_args;
wenzelm
parents: 3829
diff changeset
   124
22709
9ab51bac6287 removed obsolete TypeInfer.logicT -- use dummyT;
wenzelm
parents: 22702
diff changeset
   125
fun mixfixT (Binder _) = (dummyT --> dummyT) --> dummyT
9ab51bac6287 removed obsolete TypeInfer.logicT -- use dummyT;
wenzelm
parents: 22702
diff changeset
   126
  | mixfixT mx = replicate (mixfix_args mx) dummyT ---> dummyT;
22702
372da033ed93 added mixfixT (from type_infer.ML);
wenzelm
parents: 21805
diff changeset
   127
4053
c88d0d5ae806 added mixfix_args;
wenzelm
parents: 3829
diff changeset
   128
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   129
(* syn_ext_types *)
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   130
42293
6cca0343ea48 renamed sprop "prop#" to "prop'" -- proper identifier;
wenzelm
parents: 42288
diff changeset
   131
val typeT = Type ("type", []);
6cca0343ea48 renamed sprop "prop#" to "prop'" -- proper identifier;
wenzelm
parents: 42288
diff changeset
   132
fun make_type n = replicate n typeT ---> typeT;
35412
b8dead547d9e more uniform treatment of syntax for types vs. consts;
wenzelm
parents: 35390
diff changeset
   133
14903
d264b8ad3eec removed separate logtypes field of syntax;
wenzelm
parents: 14855
diff changeset
   134
fun syn_ext_types type_decls =
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   135
  let
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   136
    fun mk_infix sy ty t p1 p2 p3 range =
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   137
      Syntax_Ext.Mfix
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   138
        (Symbol_Pos.explode0 "(_ " @ Input.source_explode sy @ Symbol_Pos.explode0 "/ _)",
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   139
          ty, t, [p1, p2], p3, Position.set_range range);
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   140
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 32786
diff changeset
   141
    fun mfix_of (_, _, NoSyn) = NONE
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   142
      | mfix_of (t, ty, Mixfix (sy, ps, p, range)) =
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   143
          SOME (Syntax_Ext.Mfix (Input.source_explode sy, ty, t, ps, p, Position.set_range range))
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   144
      | mfix_of (t, ty, Delimfix (sy, range)) =
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   145
          SOME (Syntax_Ext.Mfix (Input.source_explode sy, ty, t, [], 1000, Position.set_range range))
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   146
      | mfix_of (t, ty, Infix (sy, p, range)) = SOME (mk_infix sy ty t (p + 1) (p + 1) p range)
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   147
      | mfix_of (t, ty, Infixl (sy, p, range)) = SOME (mk_infix sy ty t p (p + 1) p range)
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   148
      | mfix_of (t, ty, Infixr (sy, p, range)) = SOME (mk_infix sy ty t (p + 1) p p range)
42130
e10e2cce85c8 removed unclear comments stemming from ed24ba6f69aa;
wenzelm
parents: 37216
diff changeset
   149
      | mfix_of (t, _, _) = error ("Bad mixfix declaration for " ^ quote t);
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   150
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   151
    fun check_args (_, ty, mx) (SOME (Syntax_Ext.Mfix (sy, _, _, _, _, _))) =
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42287
diff changeset
   152
          if length (Term.binder_types ty) = Syntax_Ext.mfix_args sy then ()
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   153
          else
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   154
            error ("Bad number of type constructor arguments in mixfix annotation" ^
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   155
              Position.here (pos_of mx))
35351
7425aece4ee3 allow general mixfix syntax for type constructors;
wenzelm
parents: 35130
diff changeset
   156
      | check_args _ NONE = ();
7425aece4ee3 allow general mixfix syntax for type constructors;
wenzelm
parents: 35130
diff changeset
   157
7425aece4ee3 allow general mixfix syntax for type constructors;
wenzelm
parents: 35130
diff changeset
   158
    val mfix = map mfix_of type_decls;
7425aece4ee3 allow general mixfix syntax for type constructors;
wenzelm
parents: 35130
diff changeset
   159
    val _ = map2 check_args type_decls mfix;
42298
d622145603ee more accurate markup for syntax consts, notably binders which point back to the original logical entity;
wenzelm
parents: 42297
diff changeset
   160
    val consts = map (fn (t, _, _) => (t, "")) type_decls;
d622145603ee more accurate markup for syntax consts, notably binders which point back to the original logical entity;
wenzelm
parents: 42297
diff changeset
   161
  in Syntax_Ext.syn_ext (map_filter I mfix) consts ([], [], [], []) ([], []) end;
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   162
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   163
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   164
(* syn_ext_consts *)
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   165
15751
65e4790c7914 identify binder translations only once (admits remove);
wenzelm
parents: 15570
diff changeset
   166
val binder_stamp = stamp ();
21534
68f805e9db0b Binder: syntax const is determined by binder_name, not its syntax;
wenzelm
parents: 20892
diff changeset
   167
val binder_name = suffix "_binder";
15751
65e4790c7914 identify binder translations only once (admits remove);
wenzelm
parents: 15570
diff changeset
   168
59841
2551ac44150e tuned signature;
wenzelm
parents: 55763
diff changeset
   169
fun syn_ext_consts logical_types const_decls =
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   170
  let
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   171
    fun mk_infix sy ty c p1 p2 p3 range =
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   172
      [Syntax_Ext.Mfix
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   173
        (Symbol_Pos.explode0 "op " @ Input.source_explode sy,
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   174
          ty, c, [], 1000, Position.set_range range),
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   175
       Syntax_Ext.Mfix
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   176
        (Symbol_Pos.explode0 "(_ " @ Input.source_explode sy @ Symbol_Pos.explode0 "/ _)",
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   177
          ty, c, [p1, p2], p3, Position.set_range range)];
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   178
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   179
    fun binder_typ _ (Type ("fun", [Type ("fun", [_, ty2]), ty3])) =
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   180
          [Type ("idts", []), ty2] ---> ty3
14903
d264b8ad3eec removed separate logtypes field of syntax;
wenzelm
parents: 14855
diff changeset
   181
      | binder_typ c _ = error ("Bad type of binder: " ^ quote c);
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   182
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 32786
diff changeset
   183
    fun mfix_of (_, _, NoSyn) = []
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   184
      | mfix_of (c, ty, Mixfix (sy, ps, p, range)) =
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   185
          [Syntax_Ext.Mfix (Input.source_explode sy, ty, c, ps, p, Position.set_range range)]
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   186
      | mfix_of (c, ty, Delimfix (sy, range)) =
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   187
          [Syntax_Ext.Mfix (Input.source_explode sy, ty, c, [], 1000, Position.set_range range)]
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   188
      | mfix_of (c, ty, Infix (sy, p, range)) = mk_infix sy ty c (p + 1) (p + 1) p range
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   189
      | mfix_of (c, ty, Infixl (sy, p, range)) = mk_infix sy ty c p (p + 1) p range
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   190
      | mfix_of (c, ty, Infixr (sy, p, range)) = mk_infix sy ty c (p + 1) p p range
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   191
      | mfix_of (c, ty, Binder (sy, p, q, range)) =
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   192
          [Syntax_Ext.Mfix
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   193
            (Symbol_Pos.explode0 "(3" @ Input.source_explode sy @ Symbol_Pos.explode0 "_./ _)",
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   194
              binder_typ c ty, (binder_name c), [0, p], q, Position.set_range range)]
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   195
      | mfix_of (c, _, mx) =
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59841
diff changeset
   196
          error ("Bad mixfix declaration for " ^ quote c ^ Position.here (pos_of mx));
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   197
21534
68f805e9db0b Binder: syntax const is determined by binder_name, not its syntax;
wenzelm
parents: 20892
diff changeset
   198
    fun binder (c, _, Binder _) = SOME (binder_name c, c)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15421
diff changeset
   199
      | binder _ = NONE;
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   200
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19467
diff changeset
   201
    val mfix = maps mfix_of const_decls;
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19467
diff changeset
   202
    val binders = map_filter binder const_decls;
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 32786
diff changeset
   203
    val binder_trs = binders
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 42298
diff changeset
   204
      |> map (Syntax_Ext.stamp_trfun binder_stamp o Syntax_Trans.mk_binder_tr);
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 32786
diff changeset
   205
    val binder_trs' = binders
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42287
diff changeset
   206
      |> map (Syntax_Ext.stamp_trfun binder_stamp o
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 42298
diff changeset
   207
          apsnd Syntax_Trans.non_typed_tr' o Syntax_Trans.mk_binder_tr' o swap);
42298
d622145603ee more accurate markup for syntax consts, notably binders which point back to the original logical entity;
wenzelm
parents: 42297
diff changeset
   208
d622145603ee more accurate markup for syntax consts, notably binders which point back to the original logical entity;
wenzelm
parents: 42297
diff changeset
   209
    val consts = binders @ map (fn (c, _, _) => (c, "")) const_decls;
14903
d264b8ad3eec removed separate logtypes field of syntax;
wenzelm
parents: 14855
diff changeset
   210
  in
59841
2551ac44150e tuned signature;
wenzelm
parents: 55763
diff changeset
   211
    Syntax_Ext.syn_ext' logical_types mfix consts ([], binder_trs, binder_trs', []) ([], [])
14903
d264b8ad3eec removed separate logtypes field of syntax;
wenzelm
parents: 14855
diff changeset
   212
  end;
384
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   213
a8d204d8071d support for new style mixfix annotations;
wenzelm
parents:
diff changeset
   214
end;
42287
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
   215
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
   216
structure Basic_Mixfix: BASIC_MIXFIX = Mixfix;
d98eb048a2e4 discontinued special treatment of structure Mixfix;
wenzelm
parents: 42284
diff changeset
   217
open Basic_Mixfix;