src/Pure/Syntax/syn_ext.ML
author wenzelm
Wed, 30 Jan 2002 14:05:29 +0100
changeset 12865 6b3484b8d572
parent 12785 27debaf2112d
child 14647 3f9d3d5cd0cd
permissions -rw-r--r--
escape_mfix;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Syntax/syn_ext.ML
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
911
55754d6d399c new in mixfix annotations: "' " (quote space) separates delimiters without
wenzelm
parents: 865
diff changeset
     3
    Author:     Markus Wenzel and Carsten Clasohm, TU Muenchen
12785
wenzelm
parents: 12513
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     5
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     6
Syntax extension (internal interface).
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     7
*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     8
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     9
signature SYN_EXT0 =
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
    10
sig
6760
1c56eb841afe added dddot_indexname;
wenzelm
parents: 6322
diff changeset
    11
  val dddot_indexname: indexname
1c56eb841afe added dddot_indexname;
wenzelm
parents: 6322
diff changeset
    12
  val constrainC: string
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    13
  val typeT: typ
5690
4b056ee5435c no open;
wenzelm
parents: 4938
diff changeset
    14
  val max_pri: int
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
    15
end;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    16
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    17
signature SYN_EXT =
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
    18
sig
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    19
  include SYN_EXT0
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    20
  val logic: string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    21
  val args: string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    22
  val cargs: string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    23
  val any: string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    24
  val sprop: string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    25
  val typ_to_nonterm: typ -> string
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    26
  datatype xsymb =
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    27
    Delim of string |
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    28
    Argument of string * int |
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    29
    Space of string |
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    30
    Bg of int | Brk of int | En
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    31
  datatype xprod = XProd of string * xsymb list * string * int
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    32
  val chain_pri: int
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
    33
  val delims_of: xprod list -> string list list
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    34
  datatype mfix = Mfix of string * typ * string * int list * int
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    35
  datatype syn_ext =
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    36
    SynExt of {
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    37
      logtypes: string list,
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    38
      xprods: xprod list,
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    39
      consts: string list,
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2694
diff changeset
    40
      prmodes: string list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    41
      parse_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    42
      parse_rules: (Ast.ast * Ast.ast) list,
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    43
      parse_translation: (string * (term list -> term)) list,
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    44
      print_translation: (string * (bool -> typ -> term list -> term)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    45
      print_rules: (Ast.ast * Ast.ast) list,
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
    46
      print_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
6322
7047300264c9 token translation: real;
wenzelm
parents: 5870
diff changeset
    47
      token_translation: (string * string * (string -> string * real)) list}
4054
wenzelm
parents: 4050
diff changeset
    48
  val mfix_args: string -> int
12865
6b3484b8d572 escape_mfix;
wenzelm
parents: 12785
diff changeset
    49
  val escape_mfix: string -> string
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    50
  val mk_syn_ext: bool -> string list -> mfix list ->
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    51
    string list -> (string * (Ast.ast list -> Ast.ast)) list *
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    52
    (string * (term list -> term)) list *
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    53
    (string * (bool -> typ -> term list -> term)) list * (string * (Ast.ast list -> Ast.ast)) list
6322
7047300264c9 token translation: real;
wenzelm
parents: 5870
diff changeset
    54
    -> (string * string * (string -> string * real)) list
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    55
    -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    56
  val syn_ext: string list -> mfix list -> string list ->
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    57
    (string * (Ast.ast list -> Ast.ast)) list * (string * (term list -> term)) list *
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    58
    (string * (bool -> typ -> term list -> term)) list * (string * (Ast.ast list -> Ast.ast)) list
6322
7047300264c9 token translation: real;
wenzelm
parents: 5870
diff changeset
    59
    -> (string * string * (string -> string * real)) list
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    60
    -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    61
  val syn_ext_logtypes: string list -> syn_ext
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    62
  val syn_ext_const_names: string list -> string list -> syn_ext
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    63
  val syn_ext_rules: string list -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    64
  val fix_tr': (term list -> term) -> bool -> typ -> term list -> term
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    65
  val syn_ext_trfuns: string list ->
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    66
    (string * (Ast.ast list -> Ast.ast)) list * (string * (term list -> term)) list *
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    67
    (string * (term list -> term)) list * (string * (Ast.ast list -> Ast.ast)) list
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    68
    -> syn_ext
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    69
  val syn_ext_trfunsT: string list ->
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
    70
    (string * (bool -> typ -> term list -> term)) list -> syn_ext
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
    71
  val syn_ext_tokentrfuns: string list
6322
7047300264c9 token translation: real;
wenzelm
parents: 5870
diff changeset
    72
    -> (string * string * (string -> string * real)) list -> syn_ext
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    73
  val pure_ext: syn_ext
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
    74
end;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    75
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    76
structure SynExt : SYN_EXT =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    77
struct
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    78
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
    79
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    80
(** misc definitions **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    81
7472
f1208505d837 removed binding;
wenzelm
parents: 6760
diff changeset
    82
val dddot_indexname = ("dddot", 0);
6760
1c56eb841afe added dddot_indexname;
wenzelm
parents: 6322
diff changeset
    83
val constrainC = "_constrain";
1c56eb841afe added dddot_indexname;
wenzelm
parents: 6322
diff changeset
    84
1c56eb841afe added dddot_indexname;
wenzelm
parents: 6322
diff changeset
    85
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    86
(* syntactic categories *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    87
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    88
val logic = "logic";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    89
val logicT = Type (logic, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    90
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    91
val args = "args";
1178
b28c6ecc3e6d added cargs for curried function application
clasohm
parents: 1145
diff changeset
    92
val cargs = "cargs";
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    93
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    94
val typeT = Type ("type", []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    95
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
    96
val sprop = "#prop";
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
    97
val spropT = Type (sprop, []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    98
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
    99
val any = "any";
624
33b9b5da3e6f made major changes to grammar;
clasohm
parents: 555
diff changeset
   100
val anyT = Type (any, []);
33b9b5da3e6f made major changes to grammar;
clasohm
parents: 555
diff changeset
   101
780
567f1fe7ea39 removed "logic1";
wenzelm
parents: 764
diff changeset
   102
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   103
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   104
(** datatype xprod **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   105
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   106
(*Delim s: delimiter s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   107
  Argument (s, p): nonterminal s requiring priority >= p, or valued token
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   108
  Space s: some white space for printing
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   109
  Bg, Brk, En: blocks and breaks for pretty printing*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   110
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   111
datatype xsymb =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   112
  Delim of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   113
  Argument of string * int |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   114
  Space of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   115
  Bg of int | Brk of int | En;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   116
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   117
fun is_delim (Delim _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   118
  | is_delim _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   119
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   120
fun is_terminal (Delim _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   121
  | is_terminal (Argument (s, _)) = Lexicon.is_terminal s
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   122
  | is_terminal _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   123
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   124
fun is_argument (Argument _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   125
  | is_argument _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   126
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   127
fun is_index (Argument ("index", _)) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   128
  | is_index _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   129
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   130
val index = Argument ("index", 1000);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   131
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   132
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   133
(*XProd (lhs, syms, c, p):
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   134
    lhs: name of nonterminal on the lhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   135
    syms: list of symbols on the rhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   136
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   137
    p: priority of this production*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   138
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   139
datatype xprod = XProd of string * xsymb list * string * int;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   140
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   141
val max_pri = 1000;   (*maximum legal priority*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   142
val chain_pri = ~1;   (*dummy for chain productions*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   143
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   144
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   145
(* delims_of *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   146
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   147
fun delims_of xprods =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   148
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   149
    fun del_of (Delim s) = Some s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   150
      | del_of _ = None;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   151
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   152
    fun dels_of (XProd (_, xsymbs, _, _)) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   153
      mapfilter del_of xsymbs;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   154
  in
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   155
    map Symbol.explode (distinct (flat (map dels_of xprods)))
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   156
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   157
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   158
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   159
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   160
(** datatype mfix **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   161
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   162
(*Mfix (sy, ty, c, ps, p):
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   163
    sy: rhs of production as symbolic string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   164
    ty: type description of production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   165
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   166
    ps: priorities of arguments in sy
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   167
    p: priority of production*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   168
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   169
datatype mfix = Mfix of string * typ * string * int list * int;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   170
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   171
fun err_in_mfix msg (Mfix (sy, _, const, _, _)) =
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   172
  error ((if msg = "" then "" else msg ^ "\n") ^
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   173
    "in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   174
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   175
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   176
(* typ_to_nonterm *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   177
865
b38c67991122 added optional precedence for body of binder;
clasohm
parents: 780
diff changeset
   178
fun typ_to_nt _ (Type (c, _)) = c
b38c67991122 added optional precedence for body of binder;
clasohm
parents: 780
diff changeset
   179
  | typ_to_nt default _ = default;
b38c67991122 added optional precedence for body of binder;
clasohm
parents: 780
diff changeset
   180
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   181
(*get nonterminal for rhs*)
865
b38c67991122 added optional precedence for body of binder;
clasohm
parents: 780
diff changeset
   182
val typ_to_nonterm = typ_to_nt any;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   183
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   184
(*get nonterminal for lhs*)
865
b38c67991122 added optional precedence for body of binder;
clasohm
parents: 780
diff changeset
   185
val typ_to_nonterm1 = typ_to_nt logic;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   186
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   187
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   188
(* read_mixfix *)
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   189
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   190
local
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   191
  fun is_meta c = c mem ["(", ")", "/", "_", "\\<index>"];
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   192
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   193
  val scan_delim_char =
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   194
    $$ "'" |-- Scan.one ((not o Symbol.is_blank) andf Symbol.not_eof) ||
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   195
    Scan.one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.not_eof);
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   196
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   197
  val scan_sym =
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   198
    $$ "_" >> K (Argument ("", 0)) ||
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   199
    $$ "\\<index>" >> K index ||
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   200
    $$ "(" |-- Scan.any Symbol.is_digit >> (Bg o #1 o Term.read_int) ||
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   201
    $$ ")" >> K En ||
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   202
    $$ "/" -- $$ "/" >> K (Brk ~1) ||
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   203
    $$ "/" |-- Scan.any Symbol.is_blank >> (Brk o length) ||
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   204
    Scan.any1 Symbol.is_blank >> (Space o implode) ||
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   205
    Scan.repeat1 scan_delim_char >> (Delim o implode);
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   206
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   207
  val scan_symb =
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   208
    scan_sym >> Some ||
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   209
    $$ "'" -- Scan.one Symbol.is_blank >> K None;
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   210
4701
be8a8d60d962 adapted to new scanner and abroque chars;
wenzelm
parents: 4146
diff changeset
   211
  val scan_symbs = Scan.repeat scan_symb --| Scan.ahead (Scan.one (not_equal "'"));
5870
5d4fc952be47 Scan.read;
wenzelm
parents: 5690
diff changeset
   212
  val read_symbs = mapfilter I o the o Scan.read Symbol.stopper scan_symbs;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   213
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   214
  fun unique_index xsymbs =
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   215
    if length (filter is_index xsymbs) <= 1 then xsymbs
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   216
    else error "Duplicate index arguments (\\<index>)";
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   217
in
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   218
  val read_mixfix = unique_index o read_symbs o Symbol.explode;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   219
  val mfix_args = length o filter is_argument o read_mixfix;
12865
6b3484b8d572 escape_mfix;
wenzelm
parents: 12785
diff changeset
   220
  val escape_mfix = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode;
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   221
end;
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   222
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   223
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   224
(* mfix_to_xprod *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   225
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   226
fun mfix_to_xprod convert logtypes (mfix as Mfix (sy, typ, const, pris, pri)) =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   227
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   228
    fun check_pri p =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   229
      if p >= 0 andalso p <= max_pri then ()
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   230
      else err_in_mfix ("Precedence out of range: " ^ string_of_int p) mfix;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   231
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   232
    fun blocks_ok [] 0 = true
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   233
      | blocks_ok [] _ = false
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   234
      | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   235
      | blocks_ok (En :: _) 0 = false
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   236
      | blocks_ok (En :: syms) n = blocks_ok syms (n - 1)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   237
      | blocks_ok (_ :: syms) n = blocks_ok syms n;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   238
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   239
    fun check_blocks syms =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   240
      if blocks_ok syms 0 then ()
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   241
      else err_in_mfix "Unbalanced block parentheses" mfix;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   242
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   243
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   244
    val cons_fst = apfst o cons;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   245
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   246
    fun add_args [] ty [] = ([], typ_to_nonterm1 ty)
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   247
      | add_args [] _ _ = err_in_mfix "Too many precedences" mfix
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   248
      | add_args ((arg as Argument ("index", _)) :: syms) ty ps =
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   249
          cons_fst arg (add_args syms ty ps)
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   250
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   251
          cons_fst (Argument (typ_to_nonterm ty, 0)) (add_args syms tys [])
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   252
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   253
          cons_fst (Argument (typ_to_nonterm ty, p)) (add_args syms tys ps)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   254
      | add_args (Argument _ :: _) _ _ =
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   255
          err_in_mfix "More arguments than in corresponding type" mfix
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   256
      | add_args (sym :: syms) ty ps = cons_fst sym (add_args syms ty ps);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   257
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   258
    fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   259
      | rem_pri sym = sym;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   260
4054
wenzelm
parents: 4050
diff changeset
   261
    fun logify_types copy_prod (a as (Argument (s, p))) =
wenzelm
parents: 4050
diff changeset
   262
          if s mem logtypes then Argument (logic, p) else a
wenzelm
parents: 4050
diff changeset
   263
      | logify_types _ a = a;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   264
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   265
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   266
    val raw_symbs = read_mixfix sy handle ERROR => err_in_mfix "" mfix;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   267
    val args = filter (fn Argument _ => true | _ => false) raw_symbs;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   268
    val (const', typ', parse_rules) =
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   269
      if not (exists is_index args) then (const, typ, [])
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   270
      else
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   271
        let
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   272
          val c = if const <> "" then "_indexed_" ^ const
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   273
            else err_in_mfix "Missing constant name for indexed syntax" mfix;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   274
          val T = Term.range_type typ handle Match =>
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   275
            err_in_mfix "Missing structure argument for indexed syntax" mfix;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   276
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   277
          val xs = map Ast.Variable (Term.invent_names [] "x" (length args - 1));
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   278
          val i = Ast.Variable "i";
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   279
          val n = Library.find_index is_index args;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   280
          val lhs = Ast.mk_appl (Ast.Constant c) (take (n, xs) @ [i] @ drop (n, xs));
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   281
          val rhs = Ast.mk_appl (Ast.Constant const) (Ast.Appl [Ast.Constant "_struct", i] :: xs);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   282
        in (c, T, [(lhs, rhs)]) end;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   283
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   284
    val (symbs, lhs) = add_args raw_symbs typ' pris;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   285
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   286
    val copy_prod =
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   287
      lhs mem ["prop", "logic"]
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   288
        andalso const <> ""
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   289
        andalso not (null symbs)
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   290
        andalso not (exists is_delim symbs);
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   291
    val lhs' =
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   292
      if convert andalso not copy_prod then
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   293
       (if lhs mem logtypes then logic
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   294
        else if lhs = "prop" then sprop else lhs)
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   295
      else lhs;
4054
wenzelm
parents: 4050
diff changeset
   296
    val symbs' = map (logify_types copy_prod) symbs;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   297
    val xprod = XProd (lhs', symbs', const', pri);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   298
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   299
    val _ = (seq check_pri pris; check_pri pri; check_blocks symbs');
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   300
    val xprod' =
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   301
      if Lexicon.is_terminal lhs' then err_in_mfix ("Illegal lhs: " ^ lhs') mfix
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   302
      else if const <> "" then xprod
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   303
      else if length (filter is_argument symbs') <> 1 then
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   304
        err_in_mfix "Copy production must have exactly one argument" mfix
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   305
      else if exists is_terminal symbs' then xprod
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   306
      else XProd (lhs', map rem_pri symbs', "", chain_pri);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   307
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   308
  in (xprod', parse_rules) end;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   309
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   310
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   311
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   312
(** datatype syn_ext **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   313
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   314
datatype syn_ext =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   315
  SynExt of {
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   316
    logtypes: string list,
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   317
    xprods: xprod list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   318
    consts: string list,
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2694
diff changeset
   319
    prmodes: string list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
   320
    parse_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
   321
    parse_rules: (Ast.ast * Ast.ast) list,
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   322
    parse_translation: (string * (term list -> term)) list,
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
   323
    print_translation: (string * (bool -> typ -> term list -> term)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
   324
    print_rules: (Ast.ast * Ast.ast) list,
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   325
    print_ast_translation: (string * (Ast.ast list -> Ast.ast)) list,
6322
7047300264c9 token translation: real;
wenzelm
parents: 5870
diff changeset
   326
    token_translation: (string * string * (string -> string * real)) list}
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   327
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   328
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   329
(* syn_ext *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   330
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   331
fun mk_syn_ext convert logtypes mfixes consts trfuns tokentrfuns (parse_rules, print_rules) =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   332
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   333
    val (parse_ast_translation, parse_translation, print_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   334
      print_ast_translation) = trfuns;
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   335
    val logtypes' = logtypes \ "prop";
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   336
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   337
    val (xprods, parse_rules') = map (mfix_to_xprod convert logtypes') mfixes
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   338
      |> split_list |> apsnd (rev o flat);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   339
    val mfix_consts = distinct (map (fn Mfix x => #3 x) mfixes @ map (fn XProd x => #3 x) xprods);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   340
  in
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   341
    SynExt {
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   342
      logtypes = logtypes',
624
33b9b5da3e6f made major changes to grammar;
clasohm
parents: 555
diff changeset
   343
      xprods = xprods,
11546
wenzelm
parents: 9380
diff changeset
   344
      consts = consts union_string mfix_consts,
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2694
diff changeset
   345
      prmodes = distinct (map (fn (m, _, _) => m) tokentrfuns),
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   346
      parse_ast_translation = parse_ast_translation,
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   347
      parse_rules = parse_rules' @ parse_rules,
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   348
      parse_translation = parse_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   349
      print_translation = print_translation,
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   350
      print_rules = map swap parse_rules' @ print_rules,
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   351
      print_ast_translation = print_ast_translation,
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   352
      token_translation = tokentrfuns}
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   353
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   354
2382
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   355
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   356
val syn_ext = mk_syn_ext true;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   357
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   358
fun syn_ext_logtypes logtypes =
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   359
  syn_ext logtypes [] [] ([], [], [], []) [] ([], []);
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   360
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   361
fun syn_ext_const_names logtypes cs =
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   362
  syn_ext logtypes [] cs ([], [], [], []) [] ([], []);
555
a7f397a14b16 removed idT, varT, tidT, tvarT (now in lexicon.ML);
wenzelm
parents: 441
diff changeset
   363
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   364
fun syn_ext_rules logtypes rules =
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   365
  syn_ext logtypes [] [] ([], [], [], []) [] rules;
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   366
4146
00136226f74b adapted syn_ext_trfunsT;
wenzelm
parents: 4054
diff changeset
   367
fun fix_tr' f _ _ ts = f ts;
2382
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   368
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   369
fun syn_ext_trfuns logtypes (atrs, trs, tr's, atr's) =
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   370
  syn_ext logtypes [] [] (atrs, trs, map (apsnd fix_tr') tr's, atr's) [] ([], []);
2382
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   371
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   372
fun syn_ext_trfunsT logtypes tr's =
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   373
  syn_ext logtypes [] [] ([], [], tr's, []) [] ([], []);
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   374
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   375
fun syn_ext_tokentrfuns logtypes tokentrfuns =
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   376
  syn_ext logtypes [] [] ([], [], [], []) tokentrfuns ([], []);
2382
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   377
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   378
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   379
(* pure_ext *)
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   380
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   381
val pure_ext = mk_syn_ext false []
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   382
  [Mfix ("_", spropT --> propT, "", [0], 0),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   383
   Mfix ("_", logicT --> anyT, "", [0], 0),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   384
   Mfix ("_", spropT --> anyT, "", [0], 0),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   385
   Mfix ("'(_')", logicT --> logicT, "", [0], max_pri),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   386
   Mfix ("'(_')", spropT --> spropT, "", [0], max_pri),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   387
   Mfix ("_::_",  [logicT, typeT] ---> logicT, "_constrain", [4, 0], 3),
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   388
   Mfix ("_::_",  [spropT, typeT] ---> spropT, "_constrain", [4, 0], 3)]
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   389
  []
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   390
  ([], [], [], [])
2694
b98365c6e869 added token_translation interface;
wenzelm
parents: 2382
diff changeset
   391
  []
764
b60e77395d1a changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents: 624
diff changeset
   392
  ([], []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   393
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   394
end;