equal
deleted
inserted
replaced
5 Pretty printing of asts, terms, types and print (ast) translation. |
5 Pretty printing of asts, terms, types and print (ast) translation. |
6 *) |
6 *) |
7 |
7 |
8 signature BASIC_PRINTER = |
8 signature BASIC_PRINTER = |
9 sig |
9 sig |
10 val show_brackets: bool Config.T |
|
11 val show_types: bool Config.T |
10 val show_types: bool Config.T |
12 val show_sorts: bool Config.T |
11 val show_sorts: bool Config.T |
13 val show_markup: bool Config.T |
12 val show_markup: bool Config.T |
14 val show_consts_markup: bool Config.T |
13 val show_consts_markup: bool Config.T |
15 val show_structs: bool Config.T |
14 val show_structs: bool Config.T |
49 structure Printer: PRINTER = |
48 structure Printer: PRINTER = |
50 struct |
49 struct |
51 |
50 |
52 (** options for printing **) |
51 (** options for printing **) |
53 |
52 |
54 val show_brackets = Config.declare_option_bool ("show_brackets", \<^here>); |
|
55 val show_types = Config.declare_option_bool ("show_types", \<^here>); |
53 val show_types = Config.declare_option_bool ("show_types", \<^here>); |
56 val show_sorts = Config.declare_option_bool ("show_sorts", \<^here>); |
54 val show_sorts = Config.declare_option_bool ("show_sorts", \<^here>); |
57 val show_markup_default = Unsynchronized.ref false; |
55 val show_markup_default = Unsynchronized.ref false; |
58 val show_markup = Config.declare_bool ("show_markup", \<^here>) (fn _ => ! show_markup_default); |
56 val show_markup = Config.declare_bool ("show_markup", \<^here>) (fn _ => ! show_markup_default); |
59 val show_consts_markup = Config.declare_bool ("show_consts_markup", \<^here>) (K true); |
57 val show_consts_markup = Config.declare_bool ("show_consts_markup", \<^here>) (K true); |
234 markup_syntax: string -> Markup.T list, |
232 markup_syntax: string -> Markup.T list, |
235 pretty_entity: string -> Pretty.T}; |
233 pretty_entity: string -> Pretty.T}; |
236 |
234 |
237 fun pretty {type_mode, curried} ctxt prtabs (ops: pretty_ops) = |
235 fun pretty {type_mode, curried} ctxt prtabs (ops: pretty_ops) = |
238 let |
236 let |
239 val show_brackets = Config.get ctxt show_brackets; |
|
240 |
|
241 val application = |
237 val application = |
242 if type_mode then Syntax_Trans.tappl_ast_tr' |
238 if type_mode then Syntax_Trans.tappl_ast_tr' |
243 else if curried then Syntax_Trans.applC_ast_tr' |
239 else if curried then Syntax_Trans.applC_ast_tr' |
244 else Syntax_Trans.appl_ast_tr'; |
240 else Syntax_Trans.appl_ast_tr'; |
245 |
241 |
295 SOME prt => SOME [prt] |
291 SOME prt => SOME [prt] |
296 | NONE => Option.map (main p) (SOME (#trf ops a ctxt args) handle Match => NONE)) |
292 | NONE => Option.map (main p) (SOME (#trf ops a ctxt args) handle Match => NONE)) |
297 |
293 |
298 and parens p q a (symbs, args) constraint = |
294 and parens p q a (symbs, args) constraint = |
299 let |
295 let |
300 val symbs' = |
296 val symbs' = if p > q then [Block (par_block, par_bg :: symbs @ [par_en])] else symbs; |
301 if p > q orelse (show_brackets andalso q <> 1000 andalso not (is_chain symbs)) |
|
302 then [Block (par_block, par_bg :: symbs @ [par_en])] else symbs; |
|
303 val output = |
297 val output = |
304 (case constraint of |
298 (case constraint of |
305 SOME (Ast.Appl [Ast.Constant "_constrain", _, ty]) => |
299 SOME (Ast.Appl [Ast.Constant "_constrain", _, ty]) => |
306 Pretty.make_block (#constrain_block ops ty) o single |
300 Pretty.make_block (#constrain_block ops ty) o single |
307 | _ => I); |
301 | _ => I); |