Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /smlnj-lib/trunk/SExp/sexp-pp.sml
ViewVC logotype

Annotation of /smlnj-lib/trunk/SExp/sexp-pp.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4685 - (view) (download)

1 : jhr 4685 (* sexp-pp.sml
2 :     *
3 :     * COPYRIGHT (c) 2018 The Fellowship of SML/NJ (http://www.smlnj.org)
4 :     * All rights reserved.
5 :     *
6 :     * A pretty printer for SExp values.
7 :     *)
8 :    
9 :     structure SExpPP : sig
10 :    
11 :     val output : TextIOPP.stream * SExp.value -> unit
12 :    
13 :     end = struct
14 :    
15 :     structure S = SExp
16 :     structure PP = TextIOPP
17 :     structure F = Format
18 :    
19 :     fun output (strm, sexp) = let
20 :     val str = PP.string strm
21 :     fun sp () = PP.space strm 1
22 :     fun ppList [] = str "()"
23 :     | ppList [v] = (
24 :     PP.openHBox strm;
25 :     str "("; ppVal v; str ")";
26 :     PP.closeBox strm)
27 :     | ppList (v1::v2::vr) = (
28 :     PP.openHBox strm;
29 :     str "("; ppVal v1; sp();
30 :     PP.openHOVBox strm (PP.Rel 0);
31 :     ppVal v2;
32 :     List.app (fn v => (sp(); ppVal v)) vr;
33 :     str ")";
34 :     PP.closeBox strm;
35 :     PP.closeBox strm)
36 :     and ppVal (S.LIST value) = ppList (value)
37 :     | ppVal (S.SYMBOL value) = str (Atom.toString value)
38 :     | ppVal (S.BOOL value) = str (if value then "#t" else "#f")
39 :     | ppVal (S.INT value) = str (F.format "%d" [F.LINT value])
40 :     | ppVal (S.FLOAT value) = str (F.format "%g" [F.REAL value])
41 :     | ppVal (S.STRING value) = str (concat ["\"", String.toString value, "\""])
42 :     in
43 :     PP.openVBox strm (PP.Abs 0);
44 :     ppVal sexp;
45 :     PP.newline strm;
46 :     PP.closeBox strm
47 :     end
48 :    
49 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0