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