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