(* USAGE: * compilation: ocamlc .ml * usage: ledit ocaml .cmo *) let (is_empty: 't Stream.t -> bool) = fun stream -> match Stream.peek stream with | None -> true | Some _ -> false let rec (to_list: 't Stream.t -> 't list) = fun stream -> match Stream.peek stream with | None -> [] | Some t -> begin Stream.junk stream ; t::(to_list stream) end let rec (to_string: char Stream.t -> string) = fun stream -> match Stream.peek stream with | None -> "" | Some c -> begin Stream.junk stream ; (String.make 1 c) ^ (to_string stream) end let rec (get_rid_of_spaces: char Stream.t -> char Stream.t) = fun stream -> match Stream.peek stream with | None -> Stream.sempty | Some c -> begin Stream.junk stream ; match c with | ' ' | '\t' | '\n' -> get_rid_of_spaces stream | _ -> Stream.icons c (get_rid_of_spaces stream) end let (parse_with: ('a Stream.t -> 'result) -> 'a Stream.t -> bool * 'result) = fun my_parser stream -> let result = my_parser stream and bool = is_empty stream in (bool,result)