src/Pure/Syntax/syntax_ext.ML
author wenzelm
Sun, 22 Sep 2024 16:04:44 +0200
changeset 80922 e0b958719301
parent 80920 bbe2c56fe255
child 81121 7cacedbddba7
permissions -rw-r--r--
remove specific support for "expression" block markup: prefer "notation";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
     1
(*  Title:      Pure/Syntax/syntax_ext.ML
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
     2
    Author:     Makarius
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
     3
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
     4
Syntax extension as internal record.
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
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
     7
signature SYNTAX_EXT =
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
     8
sig
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
     9
  datatype mfix = Mfix of Symbol_Pos.T list * typ * string * int list * int * Position.T
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
    10
  type block = {markup: Markup.T list, consistent: bool, unbreakable: bool, indent: int}
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
    11
  val block_indent: int -> block
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    12
  datatype xsymb =
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    13
    Delim of string |
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    14
    Argument of string * int |
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    15
    Space of string |
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
    16
    Bg of block |
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
    17
    Brk of int |
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
    18
    En
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    19
  datatype xprod = XProd of string * xsymb list * string * int
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    20
  val chain_pri: int
77999
ec850750db87 tuned signature;
wenzelm
parents: 71545
diff changeset
    21
  val delims_of: xprod list -> Symbol.symbol list list
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    22
  datatype syn_ext =
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 35429
diff changeset
    23
    Syn_Ext of {
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    24
      xprods: xprod list,
80748
43c4817375bf support for syntax const dependencies, with minimal integrity checks;
wenzelm
parents: 77999
diff changeset
    25
      consts: (string * string list) list,
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    26
      parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    27
      parse_rules: (Ast.ast * Ast.ast) list,
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    28
      parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
42247
12fe41a92cd5 typed_print_translation: discontinued show_sorts argument;
wenzelm
parents: 42245
diff changeset
    29
      print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
    30
      print_rules: (Ast.ast * Ast.ast) list,
42268
01401287c3f7 discontinued user-defined token translations;
wenzelm
parents: 42267
diff changeset
    31
      print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list}
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    32
  val block_annotation: int -> Markup.T -> string -> string
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
    33
  val mfix_name: Proof.context -> Symbol_Pos.T list -> string
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    34
  val mfix_args: Proof.context -> Symbol_Pos.T list -> int
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    35
  val mixfix_args: Proof.context -> Input.source -> int
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
    36
  val escape: string -> string
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    37
  val syn_ext: Proof.context -> string list -> mfix list ->
80748
43c4817375bf support for syntax const dependencies, with minimal integrity checks;
wenzelm
parents: 77999
diff changeset
    38
    (string * string list) list -> (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    39
    (string * ((Proof.context -> term list -> term) * stamp)) list *
42247
12fe41a92cd5 typed_print_translation: discontinued show_sorts argument;
wenzelm
parents: 42245
diff changeset
    40
    (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
42268
01401287c3f7 discontinued user-defined token translations;
wenzelm
parents: 42267
diff changeset
    41
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list ->
01401287c3f7 discontinued user-defined token translations;
wenzelm
parents: 42267
diff changeset
    42
    (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    43
  val syn_ext_consts: Proof.context -> (string * string list) list -> syn_ext
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    44
  val syn_ext_rules: Proof.context -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
    45
  val syn_ext_trfuns: Proof.context ->
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    46
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    47
    (string * ((Proof.context -> term list -> term) * stamp)) list *
42247
12fe41a92cd5 typed_print_translation: discontinued show_sorts argument;
wenzelm
parents: 42245
diff changeset
    48
    (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
    49
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
    50
  val stamp_trfun: stamp -> string * 'a -> string * ('a * stamp)
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
    51
  val mk_trfun: string * 'a -> string * ('a * stamp)
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
    52
  val eq_trfun: ('a * stamp) * ('a * stamp) -> bool
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
    53
end;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    54
42288
2074b31650e6 discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
wenzelm
parents: 42268
diff changeset
    55
structure Syntax_Ext: SYNTAX_EXT =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    56
struct
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    57
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    58
(** datatype xprod **)
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
(*Delim s: delimiter s
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    61
  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
    62
  Space s: some white space for printing
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    63
  Bg, Brk, En: blocks and breaks for pretty printing*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    64
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
    65
type block = {markup: Markup.T list, consistent: bool, unbreakable: bool, indent: int};
62789
ce15dd971965 explicit property for unbreakable block;
wenzelm
parents: 62787
diff changeset
    66
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
    67
fun block_indent indent : block =
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
    68
  {markup = [], consistent = false, unbreakable = false, indent = indent};
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
    69
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    70
datatype xsymb =
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    71
  Delim of string |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    72
  Argument of string * int |
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    73
  Space of string |
80893
68a3defc73d0 clarified signature;
wenzelm
parents: 80891
diff changeset
    74
  Bg of block |
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
    75
  Brk of int |
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
    76
  En;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    77
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    78
fun is_delim (Delim _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    79
  | is_delim _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    80
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    81
fun is_terminal (Delim _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    82
  | is_terminal (Argument (s, _)) = Lexicon.is_terminal s
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    83
  | is_terminal _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    84
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    85
fun is_argument (Argument _) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    86
  | is_argument _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    87
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    88
fun is_index (Argument ("index", _)) = true
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    89
  | is_index _ = false;
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    90
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    91
val index = Argument ("index", 1000);
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
    92
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    93
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    94
(*XProd (lhs, syms, c, p):
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    95
    lhs: name of nonterminal on the lhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    96
    syms: list of symbols on the rhs of the production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    97
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    98
    p: priority of this production*)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
    99
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   100
datatype xprod = XProd of string * xsymb list * string * int;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   101
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   102
val chain_pri = ~1;   (*dummy for chain productions*)
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
fun delims_of xprods =
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   105
  fold (fn XProd (_, xsymbs, _, _) =>
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   106
    fold (fn Delim s => insert (op =) s | _ => I) xsymbs) xprods []
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   107
  |> map Symbol.explode;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   108
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
(** datatype mfix **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   112
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   113
(*Mfix (sy, ty, c, ps, p, pos):
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   114
    sy: rhs of production as symbolic text
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   115
    ty: type description of production
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   116
    c: head of parse tree
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   117
    ps: priorities of arguments in sy
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   118
    p: priority of production
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   119
    pos: source position*)
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   120
62753
76b814ccce61 tuned messages -- more positions;
wenzelm
parents: 62752
diff changeset
   121
datatype mfix = Mfix of Symbol_Pos.T list * typ * string * int list * int * Position.T;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   122
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   123
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   124
(* properties *)
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   125
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   126
fun block_annotation indent notation_markup notation_name =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   127
  let
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   128
    val (elem, props) = notation_markup |> notation_name <> "" ? Markup.name notation_name;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   129
    val kind = Properties.get props Markup.kindN;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   130
    val name = Properties.get props Markup.nameN;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   131
    val s1 = if indent = 0 then [] else ["indent=" ^ Value.print_int indent];
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   132
    val s2 =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   133
      if elem = Markup.notationN then
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   134
        [Properties.print_eq (elem, cartouche (implode_space (the_list kind @ the_list name)))]
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   135
      else raise Fail ("Bad markup element for notatio: " ^ quote elem)
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   136
  in cartouche (implode_space (s1 @ s2)) end;
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   137
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   138
fun show_names names =
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   139
  commas_quote (map (fn (name, pos) => Markup.markup (Position.markup pos) name) names);
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   140
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   141
local
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   142
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   143
open Basic_Symbol_Pos;
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   144
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   145
val err_prefix = "Error in mixfix block properties: ";
62801
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   146
val !!! = Symbol_Pos.!!! (fn () => err_prefix ^ "atom expected (identifier, numeral, cartouche)");
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   147
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   148
val scan_atom =
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   149
  Symbol_Pos.scan_ident ||
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   150
  ($$$ "-" @@@ (Symbol_Pos.scan_float || Symbol_Pos.scan_nat)) ||
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   151
  Symbol_Pos.scan_float || Symbol_Pos.scan_nat ||
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   152
  Symbol_Pos.scan_cartouche_content err_prefix;
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   153
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   154
val scan_blanks = Scan.many (Symbol.is_blank o Symbol_Pos.symbol);
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   155
val scan_item =
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   156
  scan_blanks |-- scan_atom --| scan_blanks
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   157
    >> (fn ss => (Symbol_Pos.content ss, #1 (Symbol_Pos.range ss)));
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   158
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   159
val scan_prop = scan_item -- Scan.option ($$ "=" |-- !!! scan_item);
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   160
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   161
fun get_property default0 default1 parse name props =
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   162
  (case find_first (fn ((a, _), _) => a = name) props of
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   163
    NONE => default0
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   164
  | SOME (_, NONE) => default1
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   165
  | SOME ((_, pos1), SOME (b, pos2)) =>
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   166
      (parse (b, pos2) handle Fail msg =>
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   167
        error (msg ^ " for property " ^ quote name ^ Position.here_list [pos1, pos2])));
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   168
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   169
fun parse_notation ctxt (s, pos) =
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   170
  let
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   171
    val (kind, name) =
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   172
      (case Symbol.explode_words s of
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   173
        [] => ("", "")
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   174
      | a :: bs => (a, space_implode " " bs));
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   175
    val markup =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   176
      (case try (fn () => Markup_Kind.check_notation ctxt (kind, Position.none)) () of
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   177
        SOME m => m
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   178
      | NONE =>
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   179
          error ("Bad notation kind " ^ quote kind ^ Position.here pos ^
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   180
            ", expected: " ^ commas_quote (Markup_Kind.get_notation_kinds ctxt)));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   181
  in markup |> Markup.properties (Markup.name_proper name) end;
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   182
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   183
in
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   184
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   185
fun read_properties ss =
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   186
  let
62801
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   187
    val props =
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   188
      (case Scan.error (Scan.finite Symbol_Pos.stopper (Scan.repeat scan_prop)) ss of
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   189
        (props, []) => props
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   190
      | (_, (_, pos) :: _) => error (err_prefix ^ "bad input" ^ Position.here pos));
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   191
    fun ok (_, bs) = length bs <= 1;
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   192
    val _ =
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   193
      (case AList.group (eq_fst op =) props |> filter_out ok of
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   194
        [] => ()
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   195
      | dups => error ("Duplicate properties: " ^ show_names (map #1 dups)));
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   196
  in props end;
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   197
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   198
val get_string = get_property "" "" #1;
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   199
val get_bool = get_property false true (Value.parse_bool o #1);
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   200
val get_nat = get_property 0 1 (Value.parse_nat o #1);
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   201
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   202
fun get_notation_markup ctxt =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   203
  get_property NONE (SOME Markup.notation0) (SOME o parse_notation ctxt) Markup.notationN;
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   204
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   205
end;
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   206
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   207
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   208
(* read mixfix annotations *)
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   209
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   210
local
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   211
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   212
val markup_block_begin = Markup_Kind.setup_expression (Binding.make ("mixfix_block_begin", \<^here>));
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   213
val markup_block_end = Markup_Kind.setup_expression (Binding.make ("mixfix_block_end", \<^here>));
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   214
val markup_delimiter = Markup_Kind.setup_expression (Binding.make ("mixfix_delimiter", \<^here>));
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   215
val markup_argument = Markup_Kind.setup_expression (Binding.make ("mixfix_argument", \<^here>));
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   216
val markup_space = Markup_Kind.setup_expression (Binding.make ("mixfix_space", \<^here>));
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80911
diff changeset
   217
val markup_break = Markup_Kind.setup_expression (Binding.make ("mixfix_break", \<^here>));
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   218
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   219
open Basic_Symbol_Pos;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   220
62801
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   221
val err_prefix = "Error in mixfix annotation: ";
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   222
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   223
fun scan_one pred = Scan.one (pred o Symbol_Pos.symbol);
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   224
fun scan_many pred = Scan.many (pred o Symbol_Pos.symbol);
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   225
fun scan_many1 pred = Scan.many1 (pred o Symbol_Pos.symbol);
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   226
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   227
fun reports_of_block pos = [(pos, markup_block_begin), (pos, Markup.keyword3)];
62806
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   228
62808
288c309df28d explicit warning about formal use of Unicode;
wenzelm
parents: 62806
diff changeset
   229
fun reports_of (xsym, pos) =
62806
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   230
  (case xsym of
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   231
    Delim _ => [(pos, markup_delimiter), (pos, Markup.literal)]
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   232
  | Argument _ => [(pos, markup_argument)]
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   233
  | Space _ => [(pos, markup_space)]
62806
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   234
  | Bg _ => reports_of_block pos
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   235
  | Brk _ => [(pos, markup_break), (pos, Markup.keyword3)]
510f6cb6721e more formal Markup.expression;
wenzelm
parents: 80748
diff changeset
   236
  | En => [(pos, markup_block_end), (pos, Markup.keyword3)]);
62806
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   237
80891
wenzelm
parents: 80889
diff changeset
   238
fun reports_text_of (Delim s, pos) =
62808
288c309df28d explicit warning about formal use of Unicode;
wenzelm
parents: 62806
diff changeset
   239
      if Position.is_reported pos andalso exists Symbol.is_utf8 (Symbol.explode s) then
64677
8dc24130e8fe more uniform treatment of "bad" like other messages (with serial number);
wenzelm
parents: 63933
diff changeset
   240
        [((pos, Markup.bad ()),
62808
288c309df28d explicit warning about formal use of Unicode;
wenzelm
parents: 62806
diff changeset
   241
          "Mixfix delimiter contains raw Unicode -- this is non-portable and unreliable")]
288c309df28d explicit warning about formal use of Unicode;
wenzelm
parents: 62806
diff changeset
   242
      else []
80891
wenzelm
parents: 80889
diff changeset
   243
  | reports_text_of _ = [];
62808
288c309df28d explicit warning about formal use of Unicode;
wenzelm
parents: 62806
diff changeset
   244
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   245
fun read_block_properties ctxt ss =
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   246
  let
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   247
    val props = read_properties ss;
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
   248
80922
e0b958719301 remove specific support for "expression" block markup: prefer "notation";
wenzelm
parents: 80920
diff changeset
   249
    val more_markups = the_list (get_notation_markup ctxt props);
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   250
62786
2461a58b3587 clarified treatment of properties;
wenzelm
parents: 62783
diff changeset
   251
    val markup_name = get_string Markup.markupN props;
80904
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   252
    val markup_props = props |> map_filter (fn (a, opt_b) =>
05f17df447b6 more positions;
wenzelm
parents: 80899
diff changeset
   253
      if member (op =) Markup.block_properties (#1 a) then NONE
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   254
      else SOME (a, the_default ("true", Position.none) opt_b));
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   255
    val markups =
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   256
      if markup_name <> "" then [(markup_name, map (apply2 #1) markup_props)]
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   257
      else if null markup_props then []
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   258
      else error ("Markup name required for block properties: " ^ show_names (map #1 markup_props));
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
   259
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   260
    val block: block =
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   261
     {markup = more_markups @ markups,
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   262
      consistent = get_bool Markup.consistentN props,
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   263
      unbreakable = get_bool Markup.unbreakableN props,
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   264
      indent = get_nat Markup.indentN props};
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   265
  in Bg block end
62806
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   266
  handle ERROR msg =>
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   267
    let
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   268
      val reported_texts =
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   269
        reports_of_block (#1 (Symbol_Pos.range ss))
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   270
        |> map (fn (p, m) => Markup.markup_report (Position.reported_text p m ""))
de9bf8171626 more markup;
wenzelm
parents: 62805
diff changeset
   271
    in error (msg ^ implode reported_texts) end;
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
   272
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
   273
val read_block_indent =
62789
ce15dd971965 explicit property for unbreakable block;
wenzelm
parents: 62787
diff changeset
   274
  Bg o block_indent o #1 o Library.read_int o map Symbol_Pos.symbol;
62783
75ee05386b90 explicit mixfix block properties;
wenzelm
parents: 62772
diff changeset
   275
71545
b0b16088ccf2 allow slightly odd "' " in mixfix as documented (introduced in 55754d6d399c, but broken in be8a8d60d962);
wenzelm
parents: 69584
diff changeset
   276
val is_meta = member (op =) ["'", "(", ")", "/", "_", "\<index>", Symbol.open_, Symbol.close];
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   277
63933
e149e3e320a3 more general mixfix delimiters;
wenzelm
parents: 63806
diff changeset
   278
val scan_delim =
e149e3e320a3 more general mixfix delimiters;
wenzelm
parents: 63806
diff changeset
   279
  scan_one Symbol.is_control ::: Symbol_Pos.scan_cartouche "Mixfix error: " ||
e149e3e320a3 more general mixfix delimiters;
wenzelm
parents: 63806
diff changeset
   280
  $$ "'" |-- scan_one ((not o Symbol.is_blank) andf Symbol.not_eof) >> single ||
e149e3e320a3 more general mixfix delimiters;
wenzelm
parents: 63806
diff changeset
   281
  scan_one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.not_eof) >> single;
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   282
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   283
fun scan_symbs ctxt =
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   284
  let
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   285
    val scan_sym =
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   286
      $$ "_" >> K (Argument ("", 0)) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   287
      $$ "\<index>" >> K index ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   288
      $$ "(" |--
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   289
       (Symbol_Pos.scan_cartouche_content err_prefix >> read_block_properties ctxt ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   290
        scan_many Symbol.is_digit >> read_block_indent) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   291
      $$ ")" >> K En ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   292
      $$ "/" -- $$ "/" >> K (Brk ~1) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   293
      $$ "/" |-- scan_many Symbol.is_space >> (Brk o length) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   294
      scan_many1 Symbol.is_space >> (Space o Symbol_Pos.content) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   295
      Scan.repeat1 scan_delim >> (Delim o Symbol_Pos.content o flat);
14819
4dae1cb304a4 Library.read_int;
wenzelm
parents: 14697
diff changeset
   296
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   297
    val scan_symb =
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   298
      Scan.trace scan_sym >> (fn (syms, trace) => SOME (syms, #1 (Symbol_Pos.range trace))) ||
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   299
      $$ "'" -- scan_one Symbol.is_space >> K NONE;
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   300
  in Scan.repeat scan_symb --| Scan.ahead (~$$ "'") end;
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   301
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   302
in
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   303
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   304
fun read_mfix ctxt ss =
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   305
  let
62801
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   306
    val xsymbs =
80905
47793a46d06c support for Markup.expression properties in pretty-blocks;
wenzelm
parents: 80904
diff changeset
   307
      (case Scan.error (Scan.finite Symbol_Pos.stopper (scan_symbs ctxt)) ss of
62801
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   308
        (res, []) => map_filter I res
f9d102ef13f1 clarified errors -- disallow cartouche fragments as delimiter;
wenzelm
parents: 62795
diff changeset
   309
      | (_, (_, pos) :: _) => error (err_prefix ^ "bad input" ^ Position.here pos));
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   310
    val _ = Context_Position.reports ctxt (maps reports_of xsymbs);
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   311
    val _ = Context_Position.reports_text ctxt (maps reports_text_of xsymbs);
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   312
  in xsymbs end;
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   313
80908
wenzelm
parents: 80907
diff changeset
   314
val read_mfix0 = read_mfix o Context_Position.set_visible false;
wenzelm
parents: 80907
diff changeset
   315
80911
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   316
fun mfix_name ctxt =
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   317
  read_mfix0 ctxt #> map_filter (fn (Delim s, _) => SOME s | _ => NONE) #> space_implode " ";
8ad5e6df050b block markup for specific notation, notably infix and binder;
wenzelm
parents: 80909
diff changeset
   318
80908
wenzelm
parents: 80907
diff changeset
   319
fun mfix_args ctxt ss =
wenzelm
parents: 80907
diff changeset
   320
  Integer.build (read_mfix0 ctxt ss |> fold (fn (xsymb, _) => is_argument xsymb ? Integer.add 1));
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   321
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   322
fun mixfix_args ctxt = mfix_args ctxt o Input.source_explode;
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   323
35390
efad0e364738 use simplified Syntax.escape;
wenzelm
parents: 35351
diff changeset
   324
val escape = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode;
19004
a72c7a1eb129 added mfix_delims;
wenzelm
parents: 18977
diff changeset
   325
4050
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   326
end;
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   327
543df9687d7b added mixfix_args;
wenzelm
parents: 2913
diff changeset
   328
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   329
(* mfix_to_xprod *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   330
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   331
fun mfix_to_xprod ctxt logical_types (Mfix (sy, typ, const, pris, pri, pos)) =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   332
  let
80895
wenzelm
parents: 80894
diff changeset
   333
    val nonterm_for_lhs = the_default "logic" o try dest_Type_name;
wenzelm
parents: 80894
diff changeset
   334
    val nonterm_for_rhs = the_default "any" o try dest_Type_name;
wenzelm
parents: 80894
diff changeset
   335
80899
51c338103975 proper Context_Position.report, following 5328d67ec647;
wenzelm
parents: 80897
diff changeset
   336
    val _ = Context_Position.report ctxt pos Markup.language_mixfix;
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   337
    val symbs0 = read_mfix ctxt sy;
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   338
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   339
    fun err_in_mixfix msg = error (msg ^ " in mixfix annotation" ^ Position.here pos);
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   340
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   341
    fun check_blocks [] pending bad = pending @ bad
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   342
      | check_blocks ((Bg _, pos) :: rest) pending bad = check_blocks rest (pos :: pending) bad
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   343
      | check_blocks ((En, pos) :: rest) [] bad = check_blocks rest [] (pos :: bad)
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   344
      | check_blocks ((En, _) :: rest) (_ :: pending) bad = check_blocks rest pending bad
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   345
      | check_blocks (_ :: rest) pending bad = check_blocks rest pending bad;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   346
80895
wenzelm
parents: 80894
diff changeset
   347
    fun add_args [] ty [] = ([], nonterm_for_lhs ty)
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   348
      | add_args [] _ _ = err_in_mixfix "Too many precedences"
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   349
      | add_args ((sym as (Argument ("index", _), _)) :: syms) ty ps =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   350
          add_args syms ty ps |>> cons sym
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   351
      | add_args ((Argument _, pos) :: syms) (Type ("fun", [ty, tys])) [] =
80895
wenzelm
parents: 80894
diff changeset
   352
          add_args syms tys [] |>> cons (Argument (nonterm_for_rhs ty, 0), pos)
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   353
      | add_args ((Argument _, pos) :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
80895
wenzelm
parents: 80894
diff changeset
   354
          add_args syms tys ps |>> cons (Argument (nonterm_for_rhs ty, p), pos)
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   355
      | add_args ((Argument _, _) :: _) _ _ =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   356
          err_in_mixfix "More arguments than in corresponding type"
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   357
      | add_args (sym :: syms) ty ps = add_args syms ty ps |>> cons sym;
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   358
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   359
    fun logical_args (a as (Argument (s, p))) =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   360
          if s <> "prop" andalso member (op =) logical_types s then Argument ("logic", p) else a
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   361
      | logical_args a = a;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   362
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   363
    fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   364
      | rem_pri sym = sym;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   365
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   366
    val indexes = filter (is_index o #1) symbs0;
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   367
    val _ =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   368
      if length indexes <= 1 then ()
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   369
      else error ("More than one index argument" ^ Position.here_list (map #2 indexes));
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   370
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   371
    val args = map_filter (fn (arg as Argument _, _) => SOME arg | _ => NONE) symbs0;
44470
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   372
    val (const', typ', syntax_consts, parse_rules) =
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   373
      if not (exists is_index args) then (const, typ, NONE, NONE)
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   374
      else
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   375
        let
35429
afa8cf9e63d8 authentic syntax for classes and type constructors;
wenzelm
parents: 35390
diff changeset
   376
          val indexed_const =
afa8cf9e63d8 authentic syntax for classes and type constructors;
wenzelm
parents: 35390
diff changeset
   377
            if const <> "" then const ^ "_indexed"
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   378
            else err_in_mixfix "Missing constant name for indexed syntax";
14697
5ad13d05049b improved indexed syntax / implicit structures;
wenzelm
parents: 14647
diff changeset
   379
          val rangeT = Term.range_type typ handle Match =>
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   380
            err_in_mixfix "Missing structure argument for indexed syntax";
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   381
43329
84472e198515 tuned signature: Name.invent and Name.invent_names;
wenzelm
parents: 43323
diff changeset
   382
          val xs = map Ast.Variable (Name.invent Name.context "xa" (length args - 1));
19012
wenzelm
parents: 19004
diff changeset
   383
          val (xs1, xs2) = chop (find_index is_index args) xs;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   384
          val i = Ast.Variable "i";
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   385
          val lhs =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   386
            Ast.mk_appl (Ast.Constant indexed_const)
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   387
              (xs1 @ [Ast.mk_appl (Ast.Constant "_index") [i]] @ xs2);
14697
5ad13d05049b improved indexed syntax / implicit structures;
wenzelm
parents: 14647
diff changeset
   388
          val rhs = Ast.mk_appl (Ast.Constant const) (i :: xs);
80748
43c4817375bf support for syntax const dependencies, with minimal integrity checks;
wenzelm
parents: 77999
diff changeset
   389
        in (indexed_const, rangeT, SOME (indexed_const, [const]), SOME (lhs, rhs)) end;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   390
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   391
    val (symbs1, lhs) = add_args symbs0 typ' pris;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   392
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   393
    val copy_prod =
20675
cb19d18aef01 member (op =);
wenzelm
parents: 20076
diff changeset
   394
      (lhs = "prop" orelse lhs = "logic")
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   395
        andalso const <> ""
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   396
        andalso not (null symbs1)
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   397
        andalso not (exists (is_delim o #1) symbs1);
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   398
    val lhs' =
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   399
      if copy_prod orelse lhs = "prop" andalso map #1 symbs1 = [Argument ("prop'", 0)] then lhs
42293
6cca0343ea48 renamed sprop "prop#" to "prop'" -- proper identifier;
wenzelm
parents: 42288
diff changeset
   400
      else if lhs = "prop" then "prop'"
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   401
      else if member (op =) logical_types lhs then "logic"
2364
821f44a0abba mfix_to_xprod: now uses read_charnames;
wenzelm
parents: 2254
diff changeset
   402
      else lhs;
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   403
    val symbs2 = map (apfst logical_args) symbs1;
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   404
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   405
    val _ =
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   406
      (pri :: pris) |> List.app (fn p =>
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   407
        if p >= 0 andalso p <= 1000 then ()
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   408
        else err_in_mixfix ("Precedence " ^ string_of_int p ^ " out of range"));
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   409
    val _ =
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   410
      (case check_blocks symbs2 [] [] of
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   411
        [] => ()
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   412
      | bad => error ("Unbalanced block parentheses" ^ Position.here_list bad));
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   413
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   414
    val xprod = XProd (lhs', map #1 symbs2, const', pri);
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   415
    val xprod' =
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   416
      if Lexicon.is_terminal lhs' then
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   417
        err_in_mixfix ("Illegal use of terminal " ^ quote lhs' ^ " as nonterminal")
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   418
      else if const <> "" then xprod
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   419
      else if length (filter (is_argument o #1) symbs2) <> 1 then
62762
ac039c4981b6 clarified errors: more positions;
wenzelm
parents: 62753
diff changeset
   420
        err_in_mixfix "Copy production must have exactly one argument"
62764
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   421
      else if exists (is_terminal o #1) symbs2 then xprod
ff3b8e4079bd more PIDE markup;
wenzelm
parents: 62763
diff changeset
   422
      else XProd (lhs', map (rem_pri o #1) symbs2, "", chain_pri);
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   423
44470
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   424
  in (xprod', syntax_consts, parse_rules) end;
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   425
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   426
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   427
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   428
(** datatype syn_ext **)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   429
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   430
datatype syn_ext =
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 35429
diff changeset
   431
  Syn_Ext of {
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   432
    xprods: xprod list,
80748
43c4817375bf support for syntax const dependencies, with minimal integrity checks;
wenzelm
parents: 77999
diff changeset
   433
    consts: (string * string list) list,
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
   434
    parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
   435
    parse_rules: (Ast.ast * Ast.ast) list,
21772
7c7ade4f537b advanced translation functions: Proof.context;
wenzelm
parents: 20675
diff changeset
   436
    parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
42247
12fe41a92cd5 typed_print_translation: discontinued show_sorts argument;
wenzelm
parents: 42245
diff changeset
   437
    print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
1510
4588ba1b1438 Elimination of fully-functorial style.
paulson
parents: 1178
diff changeset
   438
    print_rules: (Ast.ast * Ast.ast) list,
42268
01401287c3f7 discontinued user-defined token translations;
wenzelm
parents: 42267
diff changeset
   439
    print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list};
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   440
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   441
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   442
(* syn_ext *)
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   443
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   444
fun syn_ext ctxt logical_types mfixes consts trfuns (parse_rules, print_rules) =
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   445
  let
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   446
    val (parse_ast_translation, parse_translation, print_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   447
      print_ast_translation) = trfuns;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   448
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   449
    val xprod_results = map (mfix_to_xprod ctxt logical_types) mfixes;
44470
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   450
    val xprods = map #1 xprod_results;
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   451
    val consts' = map_filter #2 xprod_results;
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   452
    val parse_rules' = rev (map_filter #3 xprod_results);
80748
43c4817375bf support for syntax const dependencies, with minimal integrity checks;
wenzelm
parents: 77999
diff changeset
   453
    val mfix_consts = 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
   454
  in
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 35429
diff changeset
   455
    Syn_Ext {
624
33b9b5da3e6f made major changes to grammar;
clasohm
parents: 555
diff changeset
   456
      xprods = xprods,
44470
6c6c31ef6bb2 more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
wenzelm
parents: 43329
diff changeset
   457
      consts = mfix_consts @ consts' @ consts,
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   458
      parse_ast_translation = parse_ast_translation,
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   459
      parse_rules = parse_rules' @ parse_rules,
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   460
      parse_translation = parse_translation,
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   461
      print_translation = print_translation,
12513
0ffb824dc95c support for ``indexed syntax'' (using "\<index>" argument instead of "_");
wenzelm
parents: 11546
diff changeset
   462
      print_rules = map swap parse_rules' @ print_rules,
42268
01401287c3f7 discontinued user-defined token translations;
wenzelm
parents: 42267
diff changeset
   463
      print_ast_translation = print_ast_translation}
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   464
  end;
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   465
2382
e7c2bce815ba added fix_tr', syn_ext_trfunsT;
wenzelm
parents: 2364
diff changeset
   466
80897
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   467
fun syn_ext_consts ctxt consts = syn_ext ctxt [] [] consts ([], [], [], []) ([], []);
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   468
fun syn_ext_rules ctxt rules = syn_ext ctxt [] [] [] ([], [], [], []) rules;
5328d67ec647 more explicit context for syn_ext/mixfix operations, but it often degenerates to background theory;
wenzelm
parents: 80895
diff changeset
   469
fun syn_ext_trfuns ctxt trfuns = syn_ext ctxt [] [] [] trfuns ([], []);
16610
58bf09036a6d accomodate advanced trfuns;
wenzelm
parents: 15973
diff changeset
   470
15754
f867c48de2e1 added stamp_trfun, mk_trfun, eq_trfun;
wenzelm
parents: 15570
diff changeset
   471
fun stamp_trfun s (c, f) = (c, (f, s));
f867c48de2e1 added stamp_trfun, mk_trfun, eq_trfun;
wenzelm
parents: 15570
diff changeset
   472
fun mk_trfun tr = stamp_trfun (stamp ()) tr;
29318
6337d1cb2ba0 added numeral, which supercedes num, xnum, float;
wenzelm
parents: 28904
diff changeset
   473
fun eq_trfun ((_, s1: stamp), (_, s2)) = s1 = s2;
15754
f867c48de2e1 added stamp_trfun, mk_trfun, eq_trfun;
wenzelm
parents: 15570
diff changeset
   474
240
8b2a8c52242d contains remaining parts of xgram.ML and extension.ML;
wenzelm
parents:
diff changeset
   475
end;