[486] | 1 | (* Pasted from Pottier's PP compiler *) |
---|
| 2 | |
---|
| 3 | (** This module provides printing utilities. *) |
---|
| 4 | |
---|
| 5 | type punctuation = |
---|
| 6 | unit -> string |
---|
| 7 | |
---|
| 8 | type 'a printer = |
---|
| 9 | unit -> 'a -> string |
---|
| 10 | |
---|
| 11 | (* [nl] prints a newline character and a certain amount of |
---|
| 12 | whitespace that reflects the current indentation level. *) |
---|
| 13 | |
---|
| 14 | val nl: punctuation |
---|
| 15 | |
---|
| 16 | (* [indent ofs] transforms a printer into another printer |
---|
| 17 | that indents material [ofs] characters to the right. *) |
---|
| 18 | |
---|
| 19 | val indent: int -> 'a printer -> 'a printer |
---|
| 20 | |
---|
| 21 | (* [list] prints a list without any delimiters. *) |
---|
| 22 | |
---|
| 23 | val list: 'a printer -> 'a list printer |
---|
| 24 | |
---|
| 25 | (* [preclist] prints a list where a delimiter precedes every |
---|
| 26 | element. *) |
---|
| 27 | |
---|
| 28 | val preclist: punctuation -> 'a printer -> 'a list printer |
---|
| 29 | |
---|
| 30 | (* [termlist] prints a list where a delimiter terminates every |
---|
| 31 | element. *) |
---|
| 32 | |
---|
| 33 | val termlist: punctuation -> 'a printer -> 'a list printer |
---|
| 34 | |
---|
| 35 | (* [seplist] prints a list where a separator separates every two |
---|
| 36 | consecutive elements. *) |
---|
| 37 | |
---|
| 38 | val seplist: punctuation -> 'a printer -> 'a list printer |
---|
| 39 | |
---|
| 40 | (* [annlist] prints nothing if its list argument is empty, and prints |
---|
| 41 | an announcement followed by the list if the list is nonempty. *) |
---|
| 42 | |
---|
| 43 | val annlist: punctuation -> 'a list printer -> 'a list printer |
---|
| 44 | |
---|
| 45 | (* Punctuation. *) |
---|
| 46 | |
---|
| 47 | val space: punctuation |
---|
| 48 | val comma: punctuation |
---|
| 49 | val semicolon: punctuation |
---|
| 50 | val var: punctuation |
---|
| 51 | val seminl: punctuation |
---|
| 52 | val nlspace: int -> punctuation |
---|
| 53 | val nlnl: punctuation |
---|
| 54 | |
---|
| 55 | (* [atmost n delimiter stop] normally prints a [delimiter], except that, |
---|
| 56 | every [n] calls, it prints a [stop] in addition. *) |
---|
| 57 | |
---|
| 58 | val atmost: int -> punctuation -> punctuation -> punctuation |
---|
| 59 | |
---|
| 60 | (* [catenate] turns a list of columns into a single column, adding |
---|
| 61 | padding (whitespace) to enforce alignment. *) |
---|
| 62 | |
---|
| 63 | val catenate: string list list -> string list |
---|
| 64 | |
---|
| 65 | (* [transposerev] turns a reversed list of lines into a list of columns. *) |
---|
| 66 | |
---|
| 67 | val transposerev: string list list -> string list list |
---|
| 68 | |
---|
| 69 | (* [showif flag printer x] displays [x] on standard output using |
---|
| 70 | [printer] when [flag] is set. It returns [x]. *) |
---|
| 71 | |
---|
| 72 | val showif: bool -> 'a printer -> 'a -> 'a |
---|
| 73 | |
---|