src/Pure/Syntax/syn_ext.ML
author clasohm
Tue, 17 May 1994 14:42:34 +0200
changeset 373 68400ea32f7b
parent 369 5a7194eeb4ed
child 441 2b97bd6415b7
permissions -rw-r--r--
fixed a bug in syntax_error, added "Building new grammar" message; automatically generated nonterminals now start with "@"
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$
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     4
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     5
Syntax extension (internal interface).
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     6
*)
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
signature SYN_EXT0 =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     9
sig
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    10
  val typeT: typ
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    11
  val constrainC: string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    12
end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    13
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    14
signature SYN_EXT =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    15
sig
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    16
  include SYN_EXT0
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    17
  structure Ast: AST
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    18
  local open Ast in
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    19
    val logic: string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    20
    val args: string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    21
    val idT: typ
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    22
    val varT: typ
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    23
    val tidT: typ
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    24
    val tvarT: typ
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    25
    val applC: string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    26
    val typ_to_nonterm: typ -> string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    27
    datatype xsymb =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    28
      Delim of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    29
      Argument of string * int |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    30
      Space of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    31
      Bg of int | Brk of int | En
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    32
    datatype xprod = XProd of string * xsymb list * string * int
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    33
    val max_pri: int
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    34
    val chain_pri: int
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    35
    val delims_of: xprod list -> string list
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    36
    datatype mfix = Mfix of string * typ * string * int list * int
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    37
    datatype syn_ext =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    38
      SynExt of {
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    39
        roots: string list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    40
        xprods: xprod list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    41
        consts: string list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    42
        parse_ast_translation: (string * (ast list -> ast)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    43
        parse_rules: (ast * ast) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    44
        parse_translation: (string * (term list -> term)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    45
        print_translation: (string * (term list -> term)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    46
        print_rules: (ast * ast) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    47
        print_ast_translation: (string * (ast list -> ast)) list}
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    48
    val syn_ext: string list -> string list -> mfix list -> string list ->
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    49
      (string * (ast list -> ast)) list * (string * (term list -> term)) list *
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    50
      (string * (term list -> term)) list * (string * (ast list -> ast)) list
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    51
      -> (ast * ast) list * (ast * ast) list -> syn_ext
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    52
    val syn_ext_rules: string list -> (ast * ast) list * (ast * ast) list -> syn_ext
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    53
    val syn_ext_roots: string list -> string list -> syn_ext
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    54
  end
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    55
end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    56
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    57
functor SynExtFun(structure Lexicon: LEXICON and Ast: AST): SYN_EXT =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    58
struct
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    59
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    60
structure Ast = Ast;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    61
open Lexicon Ast;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    62
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    63
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    64
(** misc definitions **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    65
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    66
(* syntactic categories *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    67
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    68
val logic = "logic";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    69
val logicT = Type (logic, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    70
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    71
val logic1 = "logic1";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    72
val logic1T = Type (logic1, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    73
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    74
val args = "args";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    75
val argsT = Type (args, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    76
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    77
val typeT = Type ("type", []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    78
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    79
val funT = Type ("fun", []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    80
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    81
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    82
(* terminals *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    83
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    84
val idT = Type (id, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    85
val varT = Type (var, []);
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
    86
val tidT = Type (tid, []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    87
val tvarT = Type (tvar, []);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    88
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    89
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    90
(* constants *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    91
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    92
val applC = "_appl";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    93
val constrainC = "_constrain";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    94
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    95
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    96
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    97
(** datatype xprod **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    98
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    99
(*Delim s: delimiter s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   100
  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
   101
  Space s: some white space for printing
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   102
  Bg, Brk, En: blocks and breaks for pretty printing*)
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 xsymb =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   105
  Delim of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   106
  Argument of string * int |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   107
  Space of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   108
  Bg of int | Brk of int | En;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   109
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
(*XProd (lhs, syms, c, p):
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   112
    lhs: name of nonterminal on the lhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   113
    syms: list of symbols on the rhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   114
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   115
    p: priority of this production*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   116
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   117
datatype xprod = XProd of string * xsymb list * string * int;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   118
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   119
val max_pri = 1000;   (*maximum legal priority*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   120
val chain_pri = ~1;   (*dummy for chain productions*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   121
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   122
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   123
(* delims_of *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   124
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   125
fun delims_of xprods =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   126
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   127
    fun del_of (Delim s) = Some s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   128
      | del_of _ = None;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   129
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   130
    fun dels_of (XProd (_, xsymbs, _, _)) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   131
      mapfilter del_of xsymbs;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   132
  in
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   133
    distinct (flat (map dels_of xprods))
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   134
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   135
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   136
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   137
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   138
(** datatype mfix **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   139
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   140
(*Mfix (sy, ty, c, ps, p):
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   141
    sy: rhs of production as symbolic string
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   142
    ty: type description of production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   143
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   144
    ps: priorities of arguments in sy
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   145
    p: priority of production*)
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
datatype mfix = Mfix of string * typ * string * int list * int;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   148
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   149
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   150
(* typ_to_nonterm *)
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 typ_to_nonterm (Type (c, _)) = c
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   153
  | typ_to_nonterm _ = logic;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   154
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   155
fun typ_to_nonterm1 (Type (c, _)) = c
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   156
  | typ_to_nonterm1 _ = logic1;
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
(* mfix_to_xprod *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   160
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   161
fun mfix_to_xprod (Mfix (sy, typ, const, pris, pri)) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   162
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   163
    fun err msg =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   164
      (writeln ("Error in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   165
        error msg);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   166
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   167
    fun check_pri p =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   168
      if p >= 0 andalso p <= max_pri then ()
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   169
      else err ("precedence out of range: " ^ string_of_int p);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   170
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   171
    fun blocks_ok [] 0 = true
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   172
      | blocks_ok [] _ = false
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   173
      | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   174
      | blocks_ok (En :: _) 0 = false
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   175
      | blocks_ok (En :: syms) n = blocks_ok syms (n - 1)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   176
      | blocks_ok (_ :: syms) n = blocks_ok syms n;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   177
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   178
    fun check_blocks syms =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   179
      if blocks_ok syms 0 then ()
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   180
      else err "unbalanced block parentheses";
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   181
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   182
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   183
    fun is_meta c = c mem ["(", ")", "/", "_"];
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   184
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   185
    fun scan_delim_char ("'" :: c :: cs) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   186
          if is_blank c then err "illegal spaces in delimiter" else (c, cs)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   187
      | scan_delim_char ["'"] = err "trailing escape character"
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   188
      | scan_delim_char (chs as c :: cs) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   189
          if is_blank c orelse is_meta c then raise LEXICAL_ERROR else (c, cs)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   190
      | scan_delim_char [] = raise LEXICAL_ERROR;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   191
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   192
    val scan_symb =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   193
      $$ "_" >> K (Argument ("", 0)) ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   194
      $$ "(" -- scan_int >> (Bg o #2) ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   195
      $$ ")" >> K En ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   196
      $$ "/" -- $$ "/" >> K (Brk ~1) ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   197
      $$ "/" -- scan_any is_blank >> (Brk o length o #2) ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   198
      scan_any1 is_blank >> (Space o implode) ||
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   199
      repeat1 scan_delim_char >> (Delim o implode);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   200
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   201
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   202
    val cons_fst = apfst o cons;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   203
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   204
    fun add_args [] ty [] = ([], typ_to_nonterm1 ty)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   205
      | add_args [] _ _ = err "too many precedences"
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   206
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   207
          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
   208
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   209
          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
   210
      | add_args (Argument _ :: _) _ _ =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   211
          err "more arguments than in corresponding type"
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   212
      | 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
   213
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   214
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   215
    fun is_arg (Argument _) = true
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   216
      | is_arg _ = false;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   217
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   218
    fun is_term (Delim _) = true
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   219
      | is_term (Argument (s, _)) = is_terminal s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   220
      | is_term _ = false;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   221
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   222
    fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   223
      | rem_pri sym = sym;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   224
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   225
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   226
    val (raw_symbs, _) = repeat scan_symb (explode sy);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   227
    val (symbs, lhs) = add_args raw_symbs typ pris;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   228
    val xprod = XProd (lhs, symbs, const, pri);
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   229
  in
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   230
    seq check_pri pris;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   231
    check_pri pri;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   232
    check_blocks symbs;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   233
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   234
    if is_terminal lhs then err ("illegal lhs: " ^ lhs)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   235
    else if const <> "" then xprod
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   236
    else if length (filter is_arg symbs) <> 1 then
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   237
      err "copy production must have exactly one argument"
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   238
    else if exists is_term symbs then xprod
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   239
    else XProd (lhs, map rem_pri symbs, "", chain_pri)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   240
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   241
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
(** datatype syn_ext **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   244
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   245
datatype syn_ext =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   246
  SynExt of {
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   247
    roots: string list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   248
    xprods: xprod list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   249
    consts: string list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   250
    parse_ast_translation: (string * (ast list -> ast)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   251
    parse_rules: (ast * ast) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   252
    parse_translation: (string * (term list -> term)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   253
    print_translation: (string * (term list -> term)) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   254
    print_rules: (ast * ast) list,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   255
    print_ast_translation: (string * (ast list -> ast)) list};
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   256
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
(* syn_ext *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   259
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   260
fun syn_ext all_roots new_roots mfixes consts trfuns rules =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   261
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   262
    val (parse_ast_translation, parse_translation, print_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   263
      print_ast_translation) = trfuns;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   264
    val (parse_rules, print_rules) = rules;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   265
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   266
    val Troots = map (apr (Type, [])) new_roots;
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   267
    val Troots' = Troots \\ [typeT, propT];
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   268
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   269
    fun change_name T ext =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   270
      let val Type (name, ts) = T
373
68400ea32f7b fixed a bug in syntax_error, added "Building new grammar" message;
clasohm
parents: 369
diff changeset
   271
      in Type ("@" ^ name ^ ext, ts) end;
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   272
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   273
    (* Append "_H" to lhs if production is not a copy or chain production *)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   274
    fun hide_xprod roots (XProd (lhs, symbs, const, pri)) =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   275
      let fun is_delim (Delim _) = true
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   276
            | is_delim _ = false
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   277
      in if const <> "" andalso lhs mem roots andalso exists is_delim symbs then
373
68400ea32f7b fixed a bug in syntax_error, added "Building new grammar" message;
clasohm
parents: 369
diff changeset
   278
           XProd ("@" ^ lhs ^ "_H", symbs, const, pri)
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   279
         else XProd (lhs, symbs, const, pri)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   280
      end;
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   281
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   282
    (* Make descend production and append "_H" to rhs nonterminal *)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   283
    fun descend_right (from, to) =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   284
      Mfix ("_", change_name to "_H" --> from, "", [0], 0);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   285
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   286
    (* Make descend production and append "_H" to lhs *)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   287
    fun descend_left (from, to) =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   288
      Mfix ("_", to --> change_name from "_H", "", [0], 0);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   289
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   290
    (* Make descend production and append "_A" to lhs *)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   291
    fun descend1 (from, to) =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   292
      Mfix ("_", to --> change_name from "_A", "", [0], 0);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   293
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   294
    (* Make parentheses production for 'hidden' and 'automatic' nonterminal *)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   295
    fun parents T = 
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   296
      if T = typeT then
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   297
        [Mfix ("'(_')", T --> T, "", [0], max_pri)]
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   298
      else
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   299
        [Mfix ("'(_')", change_name T "_H" --> change_name T "_H", "", [0], max_pri),
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   300
         Mfix ("'(_')", change_name T "_A" --> change_name T "_A", "", [0], max_pri)];
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   301
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   302
    fun mkappl T =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   303
      Mfix ("(1_/(1'(_')))", [funT, argsT] ---> change_name T "_A", applC, 
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   304
            [max_pri, 0], max_pri);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   305
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   306
    fun mkid T =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   307
      Mfix ("_", idT --> change_name T "_A", "", [], max_pri);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   308
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   309
    fun mkvar T =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   310
      Mfix ("_", varT --> change_name T "_A", "", [], max_pri);
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   311
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   312
    fun constrain T =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   313
      Mfix ("_::_", [T, typeT] ---> change_name T "_A", constrainC, 
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   314
            [max_pri, 0], max_pri - 1)
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   315
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   316
    fun unhide T =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   317
      if T <> logicT then
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   318
        [Mfix ("_", change_name T "_H" --> T, "", [0], 0),
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   319
         Mfix ("_", change_name T "_A" --> T, "", [0], 0)]
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   320
      else
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   321
        [Mfix ("_", change_name T "_A" --> T, "", [0], 0)];
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   322
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   323
    val mfixes' = flat (map parents Troots) @ map mkappl Troots' @
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   324
      map mkid Troots' @ map mkvar Troots' @ map constrain Troots' @
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   325
      map (apl (logicT, descend_right)) (Troots \\ [logicT, typeT]) @
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   326
      map (apr (descend1, logic1T)) (Troots') @
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   327
      flat (map unhide (Troots \\ [typeT]));
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   328
    val mfix_consts =
368
e11b893cb7b6 moved 'filter is_xid' in syn_ext
clasohm
parents: 345
diff changeset
   329
      distinct (map (fn (Mfix (_, _, c, _, _)) => c) (mfixes @ mfixes'));
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   330
    val xprods = map mfix_to_xprod mfixes;
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   331
    val xprods' = map mfix_to_xprod mfixes';
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   332
  in
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   333
    SynExt {
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   334
      roots = new_roots,
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   335
      xprods = (map (hide_xprod (all_roots \\ ["logic", "type"])) xprods) 
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   336
               @ xprods',    (* hide only productions that weren't created
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   337
                                automatically *)
368
e11b893cb7b6 moved 'filter is_xid' in syn_ext
clasohm
parents: 345
diff changeset
   338
      consts = filter is_xid (consts union mfix_consts),
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   339
      parse_ast_translation = parse_ast_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   340
      parse_rules = parse_rules,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   341
      parse_translation = parse_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   342
      print_translation = print_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   343
      print_rules = print_rules,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   344
      print_ast_translation = print_ast_translation}
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   345
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   346
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   347
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   348
(* syn_ext_rules, syn_ext_roots *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   349
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   350
fun syn_ext_rules roots rules =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   351
  syn_ext roots [] [] [] ([], [], [], []) rules;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   352
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   353
fun syn_ext_roots all_roots new_roots =
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 240
diff changeset
   354
  syn_ext all_roots new_roots [] [] ([], [], [], []) ([], []);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   355
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   356
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   357
end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   358