Created
June 20, 2014 14:11
-
-
Save pqwy/3357b12d57c0b7db8723 to your computer and use it in GitHub Desktop.
sexp formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* 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