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

SCM Repository

[smlnj] View of /smlnj-lib/trunk/SExp/sexp-printer.sml
ViewVC logotype

View of /smlnj-lib/trunk/SExp/sexp-printer.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4685 - (download) (annotate)
Mon Aug 20 16:45:33 2018 UTC (7 months ago) by jhr
File size: 1124 byte(s)
  Added SExp pretty printer, plus a bug fix
(* sexp-printer.sml
 *
 * COPYRIGHT (c) 2011 The Fellowship of SML/NJ (http://www.smlnj.org)
 * All rights reserved.
 *
 * Author: Damon Wang (with modifications by John Reppy)
 *
 * A printer for SExp values.  This printer does not introduce any line
 * breaks.  For output that is more readable, use the SExpPP module.
 *)

structure SExpPrinter : sig

    val print : TextIO.outstream * SExp.value -> unit

  end = struct

    structure S = SExp
    structure F = Format

    fun print (strm, sexp) = let
	  fun pr s = TextIO.output(strm, s)
	  fun prList [] = pr ("()")
	    | prList [v] = (pr "("; prVal v; pr ")")
	    | prList (v::vs) = (
		pr "("; prVal v; List.app (fn v => (pr " "; prVal v)) vs; pr ")")
	  and prVal (S.LIST value) = prList (value)
	    | prVal (S.SYMBOL value) = pr (Atom.toString value)
	    | prVal (S.BOOL value) = pr (if value then "#t" else "#f")
	    | prVal (S.INT value) = pr (F.format "%d" [F.LINT value])
	    | prVal (S.FLOAT value) = pr (F.format "%g" [F.REAL value])
	    | prVal (S.STRING value) = pr (concat ["\"", String.toString value, "\""])
	  in
	    prVal sexp
	  end

  end

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