| author | blanchet | 
| Thu, 26 Jun 2014 13:35:17 +0200 | |
| changeset 57364 | c1060d10089f | 
| parent 52143 | 36ffe23b25f8 | 
| child 58854 | b979c781c2db | 
| permissions | -rw-r--r-- | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 1 | (* Title: Pure/Syntax/syntax_ext.ML | 
| 911 
55754d6d399c
new in mixfix annotations: "' " (quote space) separates delimiters without
 wenzelm parents: 
865diff
changeset | 2 | Author: Markus Wenzel and Carsten Clasohm, TU Muenchen | 
| 240 | 3 | |
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 4 | Syntax extension. | 
| 240 | 5 | *) | 
| 6 | ||
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 7 | signature SYNTAX_EXT = | 
| 4050 | 8 | sig | 
| 6760 | 9 | val dddot_indexname: indexname | 
| 35351 
7425aece4ee3
allow general mixfix syntax for type constructors;
 wenzelm parents: 
35110diff
changeset | 10 | datatype mfix = Mfix of string * typ * string * int list * int | 
| 
7425aece4ee3
allow general mixfix syntax for type constructors;
 wenzelm parents: 
35110diff
changeset | 11 | val err_in_mfix: string -> mfix -> 'a | 
| 1510 | 12 | val typ_to_nonterm: typ -> string | 
| 13 | datatype xsymb = | |
| 14 | Delim of string | | |
| 15 | Argument of string * int | | |
| 16 | Space of string | | |
| 17 | Bg of int | Brk of int | En | |
| 18 | datatype xprod = XProd of string * xsymb list * string * int | |
| 19 | val chain_pri: int | |
| 4701 | 20 | val delims_of: xprod list -> string list list | 
| 1510 | 21 | datatype syn_ext = | 
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
35429diff
changeset | 22 |     Syn_Ext of {
 | 
| 1510 | 23 | xprods: xprod list, | 
| 42298 
d622145603ee
more accurate markup for syntax consts, notably binders which point back to the original logical entity;
 wenzelm parents: 
42297diff
changeset | 24 | consts: (string * string) list, | 
| 21772 | 25 | parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list, | 
| 1510 | 26 | parse_rules: (Ast.ast * Ast.ast) list, | 
| 21772 | 27 | parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list, | 
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 28 | print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list, | 
| 1510 | 29 | print_rules: (Ast.ast * Ast.ast) list, | 
| 42268 | 30 | print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list} | 
| 19004 | 31 | val mfix_delims: string -> string list | 
| 4054 | 32 | val mfix_args: string -> int | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 33 | val escape: string -> string | 
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 34 | val syn_ext': (string -> bool) -> mfix list -> | 
| 42298 
d622145603ee
more accurate markup for syntax consts, notably binders which point back to the original logical entity;
 wenzelm parents: 
42297diff
changeset | 35 | (string * string) list -> (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list * | 
| 21772 | 36 | (string * ((Proof.context -> term list -> term) * stamp)) list * | 
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 37 | (string * ((Proof.context -> typ -> term list -> term) * stamp)) list * | 
| 42268 | 38 | (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> | 
| 39 | (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext | |
| 42298 
d622145603ee
more accurate markup for syntax consts, notably binders which point back to the original logical entity;
 wenzelm parents: 
42297diff
changeset | 40 | val syn_ext: mfix list -> (string * string) list -> | 
| 21772 | 41 | (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list * | 
| 42 | (string * ((Proof.context -> term list -> term) * stamp)) list * | |
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 43 | (string * ((Proof.context -> typ -> term list -> term) * stamp)) list * | 
| 42268 | 44 | (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> | 
| 45 | (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext | |
| 14903 | 46 | val syn_ext_rules: (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext | 
| 47 | val syn_ext_trfuns: | |
| 21772 | 48 | (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list * | 
| 49 | (string * ((Proof.context -> term list -> term) * stamp)) list * | |
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 50 | (string * ((Proof.context -> typ -> term list -> term) * stamp)) list * | 
| 21772 | 51 | (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: 
42268diff
changeset | 52 |   val stamp_trfun: stamp -> string * 'a -> string * ('a * stamp)
 | 
| 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 53 |   val mk_trfun: string * 'a -> string * ('a * stamp)
 | 
| 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 54 |   val eq_trfun: ('a * stamp) * ('a * stamp) -> bool
 | 
| 4050 | 55 | end; | 
| 240 | 56 | |
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42268diff
changeset | 57 | structure Syntax_Ext: SYNTAX_EXT = | 
| 240 | 58 | struct | 
| 59 | ||
| 2694 | 60 | |
| 240 | 61 | (** misc definitions **) | 
| 62 | ||
| 7472 | 63 | val dddot_indexname = ("dddot", 0);
 | 
| 6760 | 64 | |
| 65 | ||
| 240 | 66 | (** datatype xprod **) | 
| 67 | ||
| 68 | (*Delim s: delimiter s | |
| 69 | Argument (s, p): nonterminal s requiring priority >= p, or valued token | |
| 70 | Space s: some white space for printing | |
| 71 | Bg, Brk, En: blocks and breaks for pretty printing*) | |
| 72 | ||
| 73 | datatype xsymb = | |
| 74 | Delim of string | | |
| 75 | Argument of string * int | | |
| 76 | Space of string | | |
| 77 | Bg of int | Brk of int | En; | |
| 78 | ||
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 79 | fun is_delim (Delim _) = true | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 80 | | is_delim _ = false; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 81 | |
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 82 | fun is_terminal (Delim _) = true | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 83 | | is_terminal (Argument (s, _)) = Lexicon.is_terminal s | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 84 | | is_terminal _ = false; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 85 | |
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 86 | fun is_argument (Argument _) = true | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 87 | | is_argument _ = false; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 88 | |
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 89 | fun is_index (Argument ("index", _)) = true
 | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 90 | | is_index _ = false; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 91 | |
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 92 | val index = Argument ("index", 1000);
 | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 93 | |
| 240 | 94 | |
| 95 | (*XProd (lhs, syms, c, p): | |
| 96 | lhs: name of nonterminal on the lhs of the production | |
| 97 | syms: list of symbols on the rhs of the production | |
| 98 | c: head of parse tree | |
| 99 | p: priority of this production*) | |
| 100 | ||
| 101 | datatype xprod = XProd of string * xsymb list * string * int; | |
| 102 | ||
| 103 | val chain_pri = ~1; (*dummy for chain productions*) | |
| 104 | ||
| 105 | fun delims_of xprods = | |
| 19004 | 106 | fold (fn XProd (_, xsymbs, _, _) => | 
| 107 | fold (fn Delim s => insert (op =) s | _ => I) xsymbs) xprods [] | |
| 108 | |> map Symbol.explode; | |
| 240 | 109 | |
| 110 | ||
| 111 | ||
| 112 | (** datatype mfix **) | |
| 113 | ||
| 114 | (*Mfix (sy, ty, c, ps, p): | |
| 115 | sy: rhs of production as symbolic string | |
| 116 | ty: type description of production | |
| 117 | c: head of parse tree | |
| 118 | ps: priorities of arguments in sy | |
| 119 | p: priority of production*) | |
| 120 | ||
| 121 | datatype mfix = Mfix of string * typ * string * int list * int; | |
| 122 | ||
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 123 | fun err_in_mfix msg (Mfix (sy, _, const, _, _)) = | 
| 18678 | 124 |   cat_error msg ("in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
 | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 125 | |
| 240 | 126 | |
| 127 | (* typ_to_nonterm *) | |
| 128 | ||
| 865 | 129 | fun typ_to_nt _ (Type (c, _)) = c | 
| 130 | | typ_to_nt default _ = default; | |
| 131 | ||
| 764 
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
 clasohm parents: 
624diff
changeset | 132 | (*get nonterminal for rhs*) | 
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 133 | val typ_to_nonterm = typ_to_nt "any"; | 
| 240 | 134 | |
| 764 
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
 clasohm parents: 
624diff
changeset | 135 | (*get nonterminal for lhs*) | 
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 136 | val typ_to_nonterm1 = typ_to_nt "logic"; | 
| 240 | 137 | |
| 138 | ||
| 19004 | 139 | (* read mixfix annotations *) | 
| 4050 | 140 | |
| 141 | local | |
| 19004 | 142 | |
| 20675 | 143 | val is_meta = member (op =) ["(", ")", "/", "_", "\\<index>"];
 | 
| 19004 | 144 | |
| 145 | val scan_delim_char = | |
| 23784 
75e6b9dd5336
Symbol.not_eof/sync is superceded by Symbol.is_regular (rules out further control symbols);
 wenzelm parents: 
23660diff
changeset | 146 | $$ "'" |-- Scan.one ((not o Symbol.is_blank) andf Symbol.is_regular) || | 
| 
75e6b9dd5336
Symbol.not_eof/sync is superceded by Symbol.is_regular (rules out further control symbols);
 wenzelm parents: 
23660diff
changeset | 147 | Scan.one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.is_regular); | 
| 19004 | 148 | |
| 149 | fun read_int ["0", "0"] = ~1 | |
| 150 | | read_int cs = #1 (Library.read_int cs); | |
| 4050 | 151 | |
| 19004 | 152 | val scan_sym = | 
| 153 |   $$ "_" >> K (Argument ("", 0)) ||
 | |
| 154 | $$ "\\<index>" >> K index || | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21772diff
changeset | 155 |   $$ "(" |-- Scan.many Symbol.is_digit >> (Bg o read_int) ||
 | 
| 19004 | 156 | $$ ")" >> K En || | 
| 157 | $$ "/" -- $$ "/" >> K (Brk ~1) || | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21772diff
changeset | 158 | $$ "/" |-- Scan.many Symbol.is_blank >> (Brk o length) || | 
| 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21772diff
changeset | 159 | Scan.many1 Symbol.is_blank >> (Space o implode) || | 
| 19004 | 160 | Scan.repeat1 scan_delim_char >> (Delim o implode); | 
| 14819 | 161 | |
| 19004 | 162 | val scan_symb = | 
| 163 | scan_sym >> SOME || | |
| 164 | $$ "'" -- Scan.one Symbol.is_blank >> K NONE; | |
| 165 | ||
| 19305 | 166 | val scan_symbs = Scan.repeat scan_symb --| Scan.ahead (~$$ "'"); | 
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19305diff
changeset | 167 | val read_symbs = map_filter I o the o Scan.read Symbol.stopper scan_symbs; | 
| 4050 | 168 | |
| 19004 | 169 | fun unique_index xsymbs = | 
| 33317 | 170 | if length (filter is_index xsymbs) <= 1 then xsymbs | 
| 19004 | 171 | else error "Duplicate index arguments (\\<index>)"; | 
| 4050 | 172 | |
| 19004 | 173 | in | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 174 | |
| 19004 | 175 | val read_mfix = unique_index o read_symbs o Symbol.explode; | 
| 176 | ||
| 177 | fun mfix_delims sy = fold_rev (fn Delim s => cons s | _ => I) (read_mfix sy) []; | |
| 33317 | 178 | val mfix_args = length o filter is_argument o read_mfix; | 
| 19004 | 179 | |
| 35390 | 180 | val escape = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode; | 
| 19004 | 181 | |
| 4050 | 182 | end; | 
| 183 | ||
| 184 | ||
| 240 | 185 | (* mfix_to_xprod *) | 
| 186 | ||
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 187 | fun mfix_to_xprod is_logtype (mfix as Mfix (sy, typ, const, pris, pri)) = | 
| 240 | 188 | let | 
| 189 | fun check_pri p = | |
| 42297 
140f283266b7
discontinued Syntax.max_pri, which is not really a symbolic parameter;
 wenzelm parents: 
42294diff
changeset | 190 | if p >= 0 andalso p <= 1000 then () | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 191 |       else err_in_mfix ("Precedence out of range: " ^ string_of_int p) mfix;
 | 
| 240 | 192 | |
| 193 | fun blocks_ok [] 0 = true | |
| 194 | | blocks_ok [] _ = false | |
| 195 | | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1) | |
| 196 | | blocks_ok (En :: _) 0 = false | |
| 197 | | blocks_ok (En :: syms) n = blocks_ok syms (n - 1) | |
| 198 | | blocks_ok (_ :: syms) n = blocks_ok syms n; | |
| 199 | ||
| 200 | fun check_blocks syms = | |
| 201 | if blocks_ok syms 0 then () | |
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 202 | else err_in_mfix "Unbalanced block parentheses" mfix; | 
| 240 | 203 | |
| 204 | ||
| 205 | val cons_fst = apfst o cons; | |
| 206 | ||
| 207 | fun add_args [] ty [] = ([], typ_to_nonterm1 ty) | |
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 208 | | add_args [] _ _ = err_in_mfix "Too many precedences" mfix | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 209 |       | add_args ((arg as Argument ("index", _)) :: syms) ty ps =
 | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 210 | cons_fst arg (add_args syms ty ps) | 
| 240 | 211 |       | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
 | 
| 212 | cons_fst (Argument (typ_to_nonterm ty, 0)) (add_args syms tys []) | |
| 213 |       | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
 | |
| 214 | cons_fst (Argument (typ_to_nonterm ty, p)) (add_args syms tys ps) | |
| 215 | | add_args (Argument _ :: _) _ _ = | |
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 216 | err_in_mfix "More arguments than in corresponding type" mfix | 
| 240 | 217 | | add_args (sym :: syms) ty ps = cons_fst sym (add_args syms ty ps); | 
| 218 | ||
| 219 | fun rem_pri (Argument (s, _)) = Argument (s, chain_pri) | |
| 220 | | rem_pri sym = sym; | |
| 221 | ||
| 32785 | 222 | fun logify_types (a as (Argument (s, p))) = | 
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 223 |           if s <> "prop" andalso is_logtype s then Argument ("logic", p) else a
 | 
| 32785 | 224 | | logify_types a = a; | 
| 240 | 225 | |
| 2364 | 226 | |
| 19004 | 227 | val raw_symbs = read_mfix sy handle ERROR msg => err_in_mfix msg mfix; | 
| 33317 | 228 | val args = filter (fn Argument _ => true | _ => false) raw_symbs; | 
| 44470 
6c6c31ef6bb2
more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
 wenzelm parents: 
43329diff
changeset | 229 | 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: 
43329diff
changeset | 230 | if not (exists is_index args) then (const, typ, NONE, NONE) | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 231 | else | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 232 | let | 
| 35429 
afa8cf9e63d8
authentic syntax for classes and type constructors;
 wenzelm parents: 
35390diff
changeset | 233 | val indexed_const = | 
| 
afa8cf9e63d8
authentic syntax for classes and type constructors;
 wenzelm parents: 
35390diff
changeset | 234 | if const <> "" then const ^ "_indexed" | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 235 | else err_in_mfix "Missing constant name for indexed syntax" mfix; | 
| 14697 | 236 | val rangeT = Term.range_type typ handle Match => | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 237 | err_in_mfix "Missing structure argument for indexed syntax" mfix; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 238 | |
| 43329 
84472e198515
tuned signature: Name.invent and Name.invent_names;
 wenzelm parents: 
43323diff
changeset | 239 | val xs = map Ast.Variable (Name.invent Name.context "xa" (length args - 1)); | 
| 19012 | 240 | val (xs1, xs2) = chop (find_index is_index args) xs; | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 241 | val i = Ast.Variable "i"; | 
| 14697 | 242 | val lhs = Ast.mk_appl (Ast.Constant indexed_const) | 
| 243 | (xs1 @ [Ast.mk_appl (Ast.Constant "_index") [i]] @ xs2); | |
| 244 | val rhs = Ast.mk_appl (Ast.Constant const) (i :: xs); | |
| 44470 
6c6c31ef6bb2
more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
 wenzelm parents: 
43329diff
changeset | 245 | 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: 
11546diff
changeset | 246 | |
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 247 | val (symbs, lhs) = add_args raw_symbs typ' pris; | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 248 | |
| 2364 | 249 | val copy_prod = | 
| 20675 | 250 | (lhs = "prop" orelse lhs = "logic") | 
| 2364 | 251 | andalso const <> "" | 
| 252 | andalso not (null symbs) | |
| 253 | andalso not (exists is_delim symbs); | |
| 254 | val lhs' = | |
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 255 |       if copy_prod orelse lhs = "prop" andalso symbs = [Argument ("prop'", 0)] then lhs
 | 
| 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 256 | else if lhs = "prop" then "prop'" | 
| 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 257 | else if is_logtype lhs then "logic" | 
| 2364 | 258 | else lhs; | 
| 32785 | 259 | val symbs' = map logify_types symbs; | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 260 | val xprod = XProd (lhs', symbs', const', pri); | 
| 240 | 261 | |
| 15570 | 262 | val _ = (List.app check_pri pris; check_pri pri; check_blocks symbs'); | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 263 | val xprod' = | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 264 |       if Lexicon.is_terminal lhs' then err_in_mfix ("Illegal lhs: " ^ lhs') mfix
 | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 265 | else if const <> "" then xprod | 
| 33317 | 266 | else if length (filter is_argument symbs') <> 1 then | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 267 | err_in_mfix "Copy production must have exactly one argument" mfix | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 268 | else if exists is_terminal symbs' then xprod | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 269 | else XProd (lhs', map rem_pri symbs', "", chain_pri); | 
| 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 270 | |
| 44470 
6c6c31ef6bb2
more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
 wenzelm parents: 
43329diff
changeset | 271 | in (xprod', syntax_consts, parse_rules) end; | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 272 | |
| 240 | 273 | |
| 274 | ||
| 275 | (** datatype syn_ext **) | |
| 276 | ||
| 277 | datatype syn_ext = | |
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
35429diff
changeset | 278 |   Syn_Ext of {
 | 
| 240 | 279 | xprods: xprod list, | 
| 42298 
d622145603ee
more accurate markup for syntax consts, notably binders which point back to the original logical entity;
 wenzelm parents: 
42297diff
changeset | 280 | consts: (string * string) list, | 
| 21772 | 281 | parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list, | 
| 1510 | 282 | parse_rules: (Ast.ast * Ast.ast) list, | 
| 21772 | 283 | parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list, | 
| 42247 
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
 wenzelm parents: 
42245diff
changeset | 284 | print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list, | 
| 1510 | 285 | print_rules: (Ast.ast * Ast.ast) list, | 
| 42268 | 286 | print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list}; | 
| 240 | 287 | |
| 288 | ||
| 289 | (* syn_ext *) | |
| 290 | ||
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 291 | fun syn_ext' is_logtype mfixes consts trfuns (parse_rules, print_rules) = | 
| 240 | 292 | let | 
| 293 | val (parse_ast_translation, parse_translation, print_translation, | |
| 294 | print_ast_translation) = trfuns; | |
| 295 | ||
| 44470 
6c6c31ef6bb2
more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
 wenzelm parents: 
43329diff
changeset | 296 | val xprod_results = map (mfix_to_xprod is_logtype) mfixes; | 
| 
6c6c31ef6bb2
more accurate treatment of index syntax constants, for proper entity references in concrete notation (e.g. infix "\<oplus>\<index>");
 wenzelm parents: 
43329diff
changeset | 297 | 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: 
43329diff
changeset | 298 | 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: 
43329diff
changeset | 299 | val parse_rules' = rev (map_filter #3 xprod_results); | 
| 42298 
d622145603ee
more accurate markup for syntax consts, notably binders which point back to the original logical entity;
 wenzelm parents: 
42297diff
changeset | 300 | val mfix_consts = map (fn Mfix x => (#3 x, "")) mfixes @ map (fn XProd x => (#3 x, "")) xprods; | 
| 240 | 301 | in | 
| 37216 
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
 wenzelm parents: 
35429diff
changeset | 302 |     Syn_Ext {
 | 
| 624 | 303 | 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: 
43329diff
changeset | 304 | consts = mfix_consts @ consts' @ consts, | 
| 240 | 305 | parse_ast_translation = parse_ast_translation, | 
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 306 | parse_rules = parse_rules' @ parse_rules, | 
| 240 | 307 | parse_translation = parse_translation, | 
| 308 | print_translation = print_translation, | |
| 12513 
0ffb824dc95c
support for ``indexed syntax'' (using "\<index>" argument instead of "_");
 wenzelm parents: 
11546diff
changeset | 309 | print_rules = map swap parse_rules' @ print_rules, | 
| 42268 | 310 | print_ast_translation = print_ast_translation} | 
| 240 | 311 | end; | 
| 312 | ||
| 2382 | 313 | |
| 42293 
6cca0343ea48
renamed sprop "prop#" to "prop'" -- proper identifier;
 wenzelm parents: 
42288diff
changeset | 314 | val syn_ext = syn_ext' (K false); | 
| 555 
a7f397a14b16
removed idT, varT, tidT, tvarT (now in lexicon.ML);
 wenzelm parents: 
441diff
changeset | 315 | |
| 42268 | 316 | fun syn_ext_rules rules = syn_ext [] [] ([], [], [], []) rules; | 
| 52143 | 317 | fun syn_ext_trfuns trfuns = syn_ext [] [] trfuns ([], []); | 
| 16610 | 318 | |
| 15754 | 319 | fun stamp_trfun s (c, f) = (c, (f, s)); | 
| 320 | fun mk_trfun tr = stamp_trfun (stamp ()) tr; | |
| 29318 
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
 wenzelm parents: 
28904diff
changeset | 321 | fun eq_trfun ((_, s1: stamp), (_, s2)) = s1 = s2; | 
| 15754 | 322 | |
| 240 | 323 | end; |