Source

erlint / src / erlint.ml

Full commit
module Po = Program_options

let usage = ""

let parse_argv argv =
  let file_path = ref "" in
  let indent_spaces = ref 2 in
  let params = 
    Arg.align [ ( "-f"
		, Arg.Set_string file_path
		, "Path A file containing a list of paths to sequences (default stdin)."
                )
	      ; ( "-indent-spaces"
		, Arg.Set_int indent_spaces
		, "Int Number of spaces to indent, default is 2"
	        )
	      ]
  in
  Arg.parse params (fun _ -> ()) usage;
  { Po.file_path = if !file_path = "" then None else Some !file_path 
  ; Po.indent_spaces = !indent_spaces
  }

let list_of_stream stream =
  let rec list_of_stream' acc =
    match Stream.peek stream with
      | None ->
	List.rev acc
      | Some e -> begin
	Stream.junk stream;
	list_of_stream' (e::acc)
      end
  in
  list_of_stream' []

let main argv =
  let program_options = parse_argv argv in
  let in_chan = 
    match program_options.Po.file_path with
      | None -> stdin
      | Some path ->
	open_in path
  in
  let code_stream = Stream.of_channel in_chan in
  let code_lexed = list_of_stream (Lexer.lex code_stream) in
  Token.pp_list code_lexed;
  Formatter.format stdout code_lexed


let () = main Sys.argv