···7788let modname_of_id id = "Cell__" ^ id
991010+let is_mangled_broken orig src =
1111+ String.length orig <> String.length src
1212+ (* ||
1313+ Seq.exists2 (fun c c' ->
1414+ (c' = ' ' || c = c')) (String.to_seq orig) (String.to_seq src) *)
1515+1616+let mangle_toplevel is_toplevel orig_source deps =
1717+ let src =
1818+ if not is_toplevel then
1919+ orig_source
2020+ else
2121+ if
2222+ String.length orig_source < 2 || orig_source.[0] <> '#' || orig_source.[1] <> ' '
2323+ then (Logs.err (fun m -> m "xx Warning, ignoring toplevel block without a leading '# '.\n%!"); orig_source)
2424+ else begin
2525+ try
2626+ let s = String.sub orig_source 2 (String.length orig_source - 2) in
2727+ let list = Ocamltop.parse_toplevel s in
2828+ let buff = Buffer.create 100 in
2929+ List.iter (fun (phr, junk, output) ->
3030+ Printf.bprintf buff " %s%s\n" phr (String.make (String.length junk) ' ');
3131+ let s = List.map (fun x ->
3232+ Printf.sprintf "%s" (String.make (String.length x) ' ')) output
3333+ in
3434+ Buffer.add_string buff (String.concat "\n" s);
3535+ ()) list;
3636+ Buffer.contents buff
3737+ with e ->
3838+ Logs.err (fun m -> m "Error in mangle_toplevel: %s" (Printexc.to_string e));
3939+ let ppf = Format.err_formatter in
4040+ let _ = Location.report_exception ppf e in
4141+ orig_source
4242+ end
4343+ in
4444+ let line1 = List.map (fun id ->
4545+ Printf.sprintf "open %s" (modname_of_id id)) deps |> String.concat " " in
4646+ let line1 = line1 ^ ";;\n" in
4747+ Logs.debug (fun m -> m "Line1: %s\n%!" line1);
4848+ Logs.debug (fun m -> m "Source: %s\n%!" src);
4949+ if is_mangled_broken orig_source src
5050+ then (
5151+ Printf.printf "Warning: mangled source is broken\n%!";
5252+ Printf.printf "orig length: %d\n%!" (String.length orig_source);
5353+ Printf.printf "src length: %d\n%!" (String.length src);
5454+ failwith "broken"
5555+ );
5656+ line1, src
5757+1058module JsooTopPpx = struct
1159 open Js_of_ocaml_compiler.Stdlib
1260···673721 Some (from, to_, wdispatch source query)
674722 end
675723676676- let mangle_toplevel is_toplevel orig_source deps =
677677- let src =
678678- if not is_toplevel then
679679- orig_source
680680- else
681681- if
682682- String.length orig_source < 2 || orig_source.[0] <> '#' || orig_source.[1] <> ' '
683683- then (Logs.err (fun m -> m "xx Warning, ignoring toplevel block without a leading '# '.\n%!"); orig_source)
684684- else begin
685685- try
686686- let s = String.sub orig_source 2 (String.length orig_source - 2) in
687687- let list = Ocamltop.parse_toplevel s in
688688- let buff = Buffer.create 100 in
689689- List.iter (fun (phr, junk, output) ->
690690- Printf.bprintf buff " %s%s\n" phr (String.make (String.length junk) ' ');
691691- List.iter (fun x ->
692692- Printf.bprintf buff " %s\n" (String.make (String.length x) ' ')) output) list;
693693- Buffer.contents buff
694694- with e ->
695695- Logs.err (fun m -> m "Error in mangle_toplevel: %s" (Printexc.to_string e));
696696- let ppf = Format.err_formatter in
697697- let _ = Location.report_exception ppf e in
698698- orig_source
699699- end
700700- in
701701- let line1 = List.map (fun id ->
702702- Printf.sprintf "open %s" (modname_of_id id)) deps |> String.concat " " in
703703- let line1 = line1 ^ ";;\n" in
704704- Logs.debug (fun m -> m "Line1: %s\n%!" line1);
705705- Logs.debug (fun m -> m "Source: %s\n%!" src);
706706- line1, src
707724708725 let complete_prefix _id _deps is_toplevel source position =
709726 try begin
+1-1
lib/ocamltop.ml
···2929 let output =
3030 if is_legacy then begin
3131 legacy_warn ();
3232- List.map (fun x -> try String.sub x 2 (String.length x - 2) with _ -> "") output
3232+ output
3333 end else output
3434 in
3535 let new_pos = Lexing.lexeme_end lexbuf in