src/Pure/Syntax/printer.ML
changeset 506 e0ca460d6e51
parent 505 97eb677142d9
child 554 c7d9018cc9e6
equal deleted inserted replaced
505:97eb677142d9 506:e0ca460d6e51
   140         fun cons_str s (String s' :: syms) = String (s ^ s') :: syms
   140         fun cons_str s (String s' :: syms) = String (s ^ s') :: syms
   141           | cons_str s syms = String s :: syms;
   141           | cons_str s syms = String s :: syms;
   142 
   142 
   143         fun arg (s, p) =
   143         fun arg (s, p) =
   144           (if s = "type" then TypArg else Arg)
   144           (if s = "type" then TypArg else Arg)
   145           (if is_terminal s then 1000 else p);
   145           (if is_terminal s then max_pri else p);
   146 
   146 
   147         fun xsyms_to_syms (Delim s :: xsyms) =
   147         fun xsyms_to_syms (Delim s :: xsyms) =
   148               apfst (cons_str s) (xsyms_to_syms xsyms)
   148               apfst (cons_str s) (xsyms_to_syms xsyms)
   149           | xsyms_to_syms (Argument s_p :: xsyms) =
   149           | xsyms_to_syms (Argument s_p :: xsyms) =
   150               apfst (cons (arg s_p)) (xsyms_to_syms xsyms)
   150               apfst (cons (arg s_p)) (xsyms_to_syms xsyms)
   194     handle Symtab.DUPS cs => err_dup_fmts cs;
   194     handle Symtab.DUPS cs => err_dup_fmts cs;
   195 
   195 
   196 
   196 
   197 
   197 
   198 (** pretty term or typ asts **)
   198 (** pretty term or typ asts **)
       
   199 
       
   200 fun chain[Block(_,pr)] = chain(pr)
       
   201   | chain[Arg _] = true
       
   202   | chain _  = false;
   199 
   203 
   200 fun pretty prtab trf type_mode ast0 p0 =
   204 fun pretty prtab trf type_mode ast0 p0 =
   201   let
   205   let
   202     val trans = apply_trans "print ast translation";
   206     val trans = apply_trans "print ast translation";
   203 
   207 
   226           let val (Ts, args') = synT (symbs, args);
   230           let val (Ts, args') = synT (symbs, args);
   227           in ((if i < 0 then Pretty.fbrk else Pretty.brk i) :: Ts, args') end
   231           in ((if i < 0 then Pretty.fbrk else Pretty.brk i) :: Ts, args') end
   228       | synT (_ :: _, []) = sys_error "synT"
   232       | synT (_ :: _, []) = sys_error "synT"
   229 
   233 
   230     and parT (pr, args, p, p': int) =
   234     and parT (pr, args, p, p': int) =
   231       if p > p' orelse (!show_brackets andalso p' <> max_pri) then
   235           #1 (synT(if p > p' orelse
   232         #1 (synT ([Block (1, String "(" :: pr @ [String ")"])], args))
   236                       (!show_brackets andalso p' <> max_pri andalso
   233       else #1 (synT (pr, args))
   237                        not(chain pr))
       
   238                    then [Block (1, String "(" :: pr @ [String ")"])]
       
   239                    else pr,
       
   240                    args))
   234 
   241 
   235     and prefixT (_, a, [], _) = [Pretty.str a]
   242     and prefixT (_, a, [], _) = [Pretty.str a]
   236       | prefixT (c, _, args, p) = astT (appT (c, args), p)
   243       | prefixT (c, _, args, p) = astT (appT (c, args), p)
   237 
   244 
   238     and splitT 0 ([x], ys) = (x, ys)
   245     and splitT 0 ([x], ys) = (x, ys)