Skip to content

Instantly share code, notes, and snippets.

@pqwy
Created June 20, 2014 14:11
Show Gist options
  • Save pqwy/3357b12d57c0b7db8723 to your computer and use it in GitHub Desktop.
Save pqwy/3357b12d57c0b7db8723 to your computer and use it in GitHub Desktop.
sexp formatter
(*
* ocamlfind ocamlopt -linkpkg -syntax camlp4o
* -package lwt,lwt.syntax,lwt.unix,sexplib
* format_sexp.ml -o format_sexp
*)
open Lwt
open Sexplib
let catch f =
try Some (f ()) with _ -> None
let main fileo =
lwt input =
match fileo with
| None -> return Lwt_io.stdin
| Some file -> Lwt_io.(open_file ~mode:Input file)
in
lwt sexp =
let stream = Lwt_io.read_lines input in
Lwt_stream.fold (^) stream "" >|= Sexp.of_string in
Lwt_io.printl Sexp.(to_string_hum sexp)
let _ =
Lwt_main.run @@ main (catch @@ fun () -> Sys.argv.(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment