let input_sexp ?text_line ?text_char ?(buf_pos = 0) ic =
  let buf = String.create 1 in
  let rec loop this_parse =
    let c = input_char ic in
    buf.[0] <- c;
    let parse_res =
      try this_parse ~pos:0 ~len:1 buf
      with Parse_error pe -> reraise_parse_error pe buf_pos
    in
    match parse_res with
    | Done (sexp, _) -> sexp
    | Cont (_, this_parse) -> loop this_parse
  in
  let this_parse ~pos ~len str = parse ?text_line ?text_char ~pos ~len str in
  loop this_parse