Skip to content

Commit

Permalink
get -use-stdin working
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly authored and jordwalke committed Sep 14, 2016
1 parent 7ea0cb3 commit 8a4649a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/reason_astjson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,11 @@ type full = structure * commentWithCategory [@@deriving yojson]
let print_ast (ast:Parsetree.structure) comments =
print_endline (Yojson.Safe.to_string (full_to_yojson (ast, comments)));;

let parse_ast (filename:string) =
match (full_of_yojson (Yojson.Safe.from_file filename)) with
| Result.Ok data -> (data, false, false)
| Result.Error message -> failwith ("Provided JSON doesn't match reason AST format: " ^ message)
;;
let parse_ast use_stdin (filename:string) =
let json = if use_stdin then
Yojson.Safe.from_channel Pervasives.stdin
else (Yojson.Safe.from_file filename) in
match (full_of_yojson json) with
| Result.Ok data -> (data, false, false)
| Result.Error message -> failwith ("Provided JSON doesn't match reason AST format: " ^ message)
;;
4 changes: 2 additions & 2 deletions src/refmt_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let default_print_width = 100
let defaultImplementationParserFor use_stdin filename =
if Filename.check_suffix filename ".re" then (Reason_toolchain.JS.canonical_implementation_with_comments (Reason_toolchain.setup_lexbuf use_stdin filename), false, false)
else if Filename.check_suffix filename ".ml" then (Reason_toolchain.ML.canonical_implementation_with_comments (Reason_toolchain.setup_lexbuf use_stdin filename), true, false)
else if Filename.check_suffix filename ".json" then Reason_astjson.parse_ast filename
else if Filename.check_suffix filename ".json" then Reason_astjson.parse_ast use_stdin filename
else (
raise (Invalid_config ("Cannot determine default implementation parser for filename '" ^ filename ^ "'."))
)
Expand Down Expand Up @@ -193,7 +193,7 @@ let () =
| Some "binary" -> ocamlBinaryParser use_stdin filename false
| Some "ml" -> (Reason_toolchain.ML.canonical_implementation_with_comments (Reason_toolchain.setup_lexbuf use_stdin filename), true, false)
| Some "re" -> (Reason_toolchain.JS.canonical_implementation_with_comments (Reason_toolchain.setup_lexbuf use_stdin filename), false, false)
| Some "json" -> Reason_astjson.parse_ast filename
| Some "json" -> Reason_astjson.parse_ast use_stdin filename
| Some s -> (
raise (Invalid_config ("Invalid -parse setting for interface '" ^ s ^ "'."))
)
Expand Down

0 comments on commit 8a4649a

Please sign in to comment.