
#use "../local-install/lib/ocaml/topfind.camlp5";;
#require "compiler-libs.common" ;;
#require "camlp-streams";;
#require "oUnit";;
#require "fmt";;
#require "rresult";;
#require "pcre2";;
#require "bos";;
(*
#require "camlp5.pa_op";;
Pcaml.inter_phrases := Some ";;\n";;
 *)
#require "camlp5.pa_r";;
Pcaml.inter_phrases := Some ";\n";;

(*
#require "camlp5.pr_o";;
 *)

#require "camlp5.pr_r";;
Pcaml.inter_phrases := Some ";\n";;


#require "camlp5.parser_quotations";;
(*
#require "camlp5.extfun";;
#require "camlp5.extend";;
#require "camlp5.phony_quotations" ;;
*)

#directory "../main";;
Exparser.optim := false ;;

#load "testutil.cmo";;
#load "testutil2.cmo";;

open OUnit2 ;;
open Testutil ;;
open Testutil2 ;;

#load "roundtrip_lexer.cmo";;
open Roundtrip_lexer ;;

let pp_plexing_lexbuf b = Fmt.(pf stdout "<<%s>>" (Plexing.Lexbuf.get b)) ;;
#install_printer pp_plexing_lexbuf ;;

(*
#load "papr_matrix_test.cmo" ;;
#load "r2r_test.cmo" ;;
*)

let pp_loc (loc : Location.t) = Format.print_string "<loc>" ;;
#install_printer pp_loc ;;

let pp_char_stream strm =
  let l = Stream.npeek !Toploop.max_printer_depth strm in
  Fmt.(pf stdout "<strm<[%a]>>" (list char) l)
;;
#install_printer pp_char_stream ;;

let pp_token_stream strm =
  let l = Stream.npeek !Toploop.max_printer_depth strm in
  let rec trim_eoi = function
    ("EOI",_ as x)::_ -> [x]
  | h::t -> h::(trim_eoi t)
  | [] -> []
  in 
  Fmt.(pf stdout "<strm<[%a]>>" (list ~sep:comma (parens (pair ~sep:comma (quote string) (quote string)))) (trim_eoi l))
;;
#install_printer pp_token_stream ;;

let lexbuf_contents lb =
  let open Lexing in
  let pos = lb.lex_curr_pos in
  let len = lb.lex_buffer_len - lb.lex_curr_pos in
  (Bytes.to_string (Bytes.sub lb.lex_buffer pos len))
;;

let pp_lexbuf lb =
  Format.print_string "#<lexbuf:<";
  Format.print_string (lexbuf_contents lb);
  Format.print_string ">>"
;;
#install_printer pp_lexbuf ;;

open Asttypes ;;
open Parsetree ;;
open Longident ;;

let pp_ctyp ty = Fmt.(pf stdout "#<ctyp< %s >>" (Eprinter.apply Pcaml.pr_ctyp Pprintf.empty_pc ty));;
let pp_expr ty = Fmt.(pf stdout "#<expr< %s >>" (Eprinter.apply Pcaml.pr_expr Pprintf.empty_pc ty));;
let pp_patt ty = Fmt.(pf stdout "#<patt< %s >>" (Eprinter.apply Pcaml.pr_patt Pprintf.empty_pc ty));;

let pp_str_item ty = Fmt.(pf stdout "#<str_item< %s >>" (Eprinter.apply Pcaml.pr_str_item Pprintf.empty_pc ty));;
let pp_sig_item ty = Fmt.(pf stdout "#<sig_item< %s >>" (Eprinter.apply Pcaml.pr_sig_item Pprintf.empty_pc ty));;
(*
let pp_ctyp ty = Fmt.(pf stdout "#<ctyp< %a >>" Pa_ppx_base.Pp_MLast.pp_ctyp ty);;
let pp_expr ty = Fmt.(pf stdout "#<expr< %a >>" Pa_ppx_base.Pp_MLast.pp_expr ty);;
let pp_patt ty = Fmt.(pf stdout "#<patt< %a >>" Pa_ppx_base.Pp_MLast.pp_patt ty);;
*)
(*
#install_printer pp_ctyp ;;
#install_printer pp_expr ;;
#install_printer pp_patt ;;
#install_printer pp_str_item ;;
#install_printer pp_sig_item ;;
*)

print_string "================ START ================\n";; flush stdout ;;


let parse_antiquot ep s =
    Ploc.call_with Plexer.force_antiquot_loc true
    (Grammar.Entry.parse ep) (Stream.of_string s)
;;

(*
;;; Local Variables: ***
;;; mode:tuareg ***
;;; End: ***

*)
