-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathppdevstring.sml
63 lines (48 loc) · 1.53 KB
/
ppdevstring.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(* $Id$
*
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the "BSD License" which is distributed with the
* software in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
* License for more details.
*
* Based on devices in the SML/NJ PP library.
*)
structure PPDevString : sig
include PP_DEVICE
val openDev : {dst: string, wid : int} -> device
val toString : device -> string
end
=
struct
datatype device = DEV of {
dst : string list ref,
wid : int
}
(* no style support *)
type style = unit
fun sameStyle _ = true
fun pushStyle _ = ()
fun popStyle _ = ()
fun defaultStyle _ = ()
fun openDev {dst, wid} = DEV {dst=ref [dst], wid=wid}
fun toString (DEV {dst, ...}) = String.concat (rev (!dst))
(* maximum printing depth (in terms of boxes) *)
fun depth _ = NONE
(* the width of the device *)
fun lineWidth (DEV{wid, ...}) = SOME wid
(* the suggested maximum width of text on a line *)
fun textWidth _ = NONE
fun add (DEV{dst, ...}, str) = (dst := str :: (!dst))
fun space (dev, n) = add (dev, StringCvt.padLeft #" " n "")
fun newline dev = add (dev, "\n")
fun string (dev, s) = add (dev, s)
fun char (dev, c) = add (dev, Char.toString c)
fun flush _ = ()
end;