Shells in OCaml
at main 53 lines 1.6 kB view raw
1open Eio.Std 2(** Shell evaluation. 3 4 This module provides the main evaluator for any shell. It requires users to 5 provide a {! Types.State} module and a {! Types.Exec} module. *) 6 7module Make (S : Types.State) (E : Types.Exec) : sig 8 type ctx 9 (** The context of the evaluation *) 10 11 module J : Types.Job with type process = E.process 12 13 val make_ctx : 14 ?interactive:bool -> 15 ?subshell:bool -> 16 ?local_state:(string * string) list -> 17 ?background_jobs:J.t list -> 18 ?last_background_process:string -> 19 ?functions:(string * Sast.compound_command) list -> 20 ?rdrs:Types.redirect list -> 21 ?exit_handler:(unit -> unit) -> 22 ?options:Built_ins.Options.t -> 23 ?hash:Hash.t -> 24 ?in_double_quotes:bool -> 25 ?umask:int -> 26 fs:Eio.Fs.dir_ty Eio.Path.t -> 27 stdin:Eio_unix.source_ty r -> 28 stdout:Eio_unix.sink_ty r -> 29 async_switch:Switch.t -> 30 program:string -> 31 argv:string array -> 32 signal_handler:((unit -> unit) -> unit) -> 33 S.t -> 34 E.t -> 35 ctx 36 37 val fs : ctx -> Eio.Fs.dir_ty Eio.Path.t 38 (** The file system capability *) 39 40 val state : ctx -> S.t 41 (** Return the current state of the context. *) 42 43 val sigint_set : ctx -> bool 44 (** Has the signal SIGINT been set via a trap. *) 45 46 val run : ctx Exit.t -> Ast.t -> ctx Exit.t * Ast.t list 47 (** [run ctx ast] evaluates [ast] using the initial [ctx]. *) 48 49 (** {2 Private} *) 50 51 val word_expansion : ctx -> Ast.word_cst -> ctx Exit.t * Ast.fragments list 52 (* Mostly for testing purposes, this exposes the logic for expanding words. *) 53end