···724724 Yojson.Safe.pretty_print ppf yjs
725725end
726726727727-let of_string s =
728728- let f = Morbig.parse_string "-" s in
729729- (* Fmt.pr "MORBIG====\n%!"; *)
730730- (* Morbig.JsonHelpers.save_as_json true Out_channel.stdout f; *)
731731- (* Fmt.pr "MORBIG====\n%!"; *)
727727+let () =
728728+ Printexc.register_printer (function
729729+ | Morbig.Errors.DuringParsing pos ->
730730+ Some
731731+ (Fmt.str "Error during parsing (potentially non-POSIX): %s"
732732+ (Morbig.string_of_lexing_position pos))
733733+ | Morbig.Errors.DuringLexing (pos, s) ->
734734+ Some
735735+ (Fmt.str "Error during lexing of \"%s\": %s" s
736736+ (Morbig.string_of_lexing_position pos))
737737+ | Morbig.Errors.DuringAliasing (pos, s) ->
738738+ Some
739739+ (Fmt.str "Error during aliasing of \"%s\": %s" s
740740+ (Morbig.string_of_lexing_position pos))
741741+ | _ -> None)
742742+743743+let of_string ?(filename = "-") s =
744744+ let f = Morbig.parse_string filename s in
732745 of_program f
733746734747let of_file path =
735748 let fname = Eio.Path.native_exn path in
736736-737737- let f = Eio.Path.load path |> Morbig.parse_string fname in
738738- (* Fmt.pr "MORBIG====\n%!"; *)
739739- (* Morbig.JsonHelpers.save_as_json true Out_channel.stdout f; *)
740740- (* Fmt.pr "MORBIG====\n%!"; *)
741741- of_program f
749749+ Eio.Path.load path |> of_string ~filename:fname
742750743751let rec word_component_to_string : word_component -> string = function
744752 | WordName s -> s
+1-1
src/lib/ast.mli
···99val of_program : Morbig.CST.program -> t
1010(** An AST from a Morbig program *)
11111212-val of_string : string -> t
1212+val of_string : ?filename:string -> string -> t
1313(** Construct an AST from a string *)
14141515val of_file : _ Eio.Path.t -> t
+12-1
src/lib/eunix.ml
···1717 let host = Unix.gethostname () in
1818 Fmt.str "%s@%s" name host
19192020+external getpgrp : unit -> int = "caml_merry_getpgrp"
2121+external tcgetpgrp : Unix.file_descr -> int = "caml_merry_tcgetpgrp"
2022external tcsetpgrp : int -> int -> int = "caml_merry_tcsetpgrp"
21232224let delegate_control ~pgid fn =
2325 let shell_pid = Unix.getpid () in
2426 Fun.protect
2527 ~finally:(fun () ->
2828+ Fmt.pr "Back to the shell\n%!";
2629 let _ : int = tcsetpgrp 0 shell_pid in
2730 ())
2831 (fun () ->
3232+ Fmt.pr "Delegating...\n%!";
2933 match tcsetpgrp (Obj.magic Unix.stdin : int) pgid with
3034 | 0 -> fn ()
3135 | n -> Fmt.failwith "tcsetpgrp: %i" n)
32363337external setpgrp : int -> int -> int = "caml_merry_setpgid"
34383535-let make_process_group () = match setpgrp 0 0 with 0 -> () | n -> exit n
3939+let make_process_group () =
4040+ let pgrp = getpgrp () in
4141+ let fg_prgp = tcgetpgrp Unix.stdin in
4242+ if Int.equal pgrp fg_prgp then
4343+ match setpgrp 0 0 with
4444+ | 0 -> ()
4545+ | _ -> assert false
4646+ | exception Unix.Unix_error (Unix.EPERM, _, _) -> ()
36473748let background () =
3849 let _pgrid = Unix.getpid () in
+1-1
src/lib/eval.ml
···1244124412451245 and run ctx ast =
12461246 (* Make the shell its own process group *)
12471247- (* Eunix.make_process_group (); *)
12471247+ Eunix.make_process_group ();
12481248 let ctx, cs =
12491249 let rec loop_commands (ctx, cs) (c : Ast.complete_commands) =
12501250 match c with
+20
src/lib/merry_stubs.c
···22#include <caml/memory.h>
33#include <caml/alloc.h>
44#include <caml/fail.h>
55+#include <caml/unixsupport.h>
5667#include <unistd.h>
78#include <signal.h>
···1415 res = tcsetpgrp(Int_val(v_fd), Long_val(v_pid_t));
15161617 CAMLreturn(Val_int(res));
1818+}
1919+2020+value caml_merry_tcgetpgrp(value v_fd) {
2121+ CAMLparam1(v_fd);
2222+ int res;
2323+2424+ res = tcgetpgrp(Long_val(v_fd));
2525+2626+ CAMLreturn(Val_long(res));
1727}
18281929value caml_merry_setpgid(value v_fd, value v_pid_t) {
···2131 int res;
22322333 res = setpgid(Long_val(v_fd), Long_val(v_pid_t));
3434+3535+ if (res == -1) caml_uerror("setpgid", Nothing);
24362537 CAMLreturn(Val_int(res));
2638}
27394040+value caml_merry_getpgrp (value v_unit) {
4141+ CAMLparam1(v_unit);
4242+ int res;
4343+4444+ res = getpgrp();
4545+4646+ CAMLreturn(Val_long(res));
4747+}