195 mapfilter (fn mode => assoc (prtabs, mode)) (modes @ [""]); |
195 mapfilter (fn mode => assoc (prtabs, mode)) (modes @ [""]); |
196 |
196 |
197 |
197 |
198 (* xprod_to_fmt *) |
198 (* xprod_to_fmt *) |
199 |
199 |
200 fun xprod_to_fmt (SynExt.XProd (_, _, "", _)) = None |
200 fun xprod_to_fmt (SynExt.XProd (_, _, "", _)) = NONE |
201 | xprod_to_fmt (SynExt.XProd (_, xsymbs, const, pri)) = |
201 | xprod_to_fmt (SynExt.XProd (_, xsymbs, const, pri)) = |
202 let |
202 let |
203 fun cons_str s (String s' :: syms) = String (s ^ s') :: syms |
203 fun cons_str s (String s' :: syms) = String (s ^ s') :: syms |
204 | cons_str s syms = String s :: syms; |
204 | cons_str s syms = String s :: syms; |
205 |
205 |
231 | nargs (Break _ :: syms) = nargs syms |
231 | nargs (Break _ :: syms) = nargs syms |
232 | nargs (Block (_, bsyms) :: syms) = nargs syms + nargs bsyms |
232 | nargs (Block (_, bsyms) :: syms) = nargs syms + nargs bsyms |
233 | nargs [] = 0; |
233 | nargs [] = 0; |
234 in |
234 in |
235 (case xsyms_to_syms xsymbs of |
235 (case xsyms_to_syms xsymbs of |
236 (symbs, []) => Some (const, (symbs, nargs symbs, pri)) |
236 (symbs, []) => SOME (const, (symbs, nargs symbs, pri)) |
237 | _ => sys_error "xprod_to_fmt: unbalanced blocks") |
237 | _ => sys_error "xprod_to_fmt: unbalanced blocks") |
238 end; |
238 end; |
239 |
239 |
240 |
240 |
241 (* empty, extend, merge prtabs *) |
241 (* empty, extend, merge prtabs *) |
267 let |
267 let |
268 val trans = apply_trans "print ast translation"; |
268 val trans = apply_trans "print ast translation"; |
269 |
269 |
270 fun token_trans c [Ast.Variable x] = |
270 fun token_trans c [Ast.Variable x] = |
271 (case tokentrf c of |
271 (case tokentrf c of |
272 None => None |
272 NONE => NONE |
273 | Some f => Some (f x)) |
273 | SOME f => SOME (f x)) |
274 | token_trans _ _ = None; |
274 | token_trans _ _ = NONE; |
275 |
275 |
276 (*default applications: prefix / postfix*) |
276 (*default applications: prefix / postfix*) |
277 val appT = |
277 val appT = |
278 if type_mode then TypeExt.tappl_ast_tr' |
278 if type_mode then TypeExt.tappl_ast_tr' |
279 else if curried then SynTrans.applC_ast_tr' |
279 else if curried then SynTrans.applC_ast_tr' |
337 else if nargs > n andalso not type_mode then |
337 else if nargs > n andalso not type_mode then |
338 astT (appT (splitT n ([c], args)), p) |
338 astT (appT (splitT n ([c], args)), p) |
339 else prnt (prnps, tbs); |
339 else prnt (prnps, tbs); |
340 in |
340 in |
341 (case token_trans a args of (*try token translation function*) |
341 (case token_trans a args of (*try token translation function*) |
342 Some s_len => [Pretty.raw_str s_len] |
342 SOME s_len => [Pretty.raw_str s_len] |
343 | None => (*try print translation functions*) |
343 | NONE => (*try print translation functions*) |
344 astT (trans a (trf a) args, p) handle Match => prnt ([], tabs)) |
344 astT (trans a (trf a) args, p) handle Match => prnt ([], tabs)) |
345 end |
345 end |
346 |
346 |
347 and astT (c as Ast.Constant a, p) = combT (c, a, [], p) |
347 and astT (c as Ast.Constant a, p) = combT (c, a, [], p) |
348 | astT (Ast.Variable x, _) = [Pretty.str x] |
348 | astT (Ast.Variable x, _) = [Pretty.str x] |