Shells in OCaml
at wip 54 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 ?last_pipeline_status:int -> 20 ?functions:(string * Sast.compound_command) list -> 21 ?rdrs:Types.redirect list -> 22 ?exit_handler:(unit -> unit) -> 23 ?options:Built_ins.Options.t -> 24 ?hash:Hash.t -> 25 ?in_double_quotes:bool -> 26 ?umask:int -> 27 fs:Eio.Fs.dir_ty Eio.Path.t -> 28 stdin:Eio_unix.source_ty r -> 29 stdout:Eio_unix.sink_ty r -> 30 async_switch:Switch.t -> 31 program:string -> 32 argv:string array -> 33 signal_handler:((unit -> unit) -> unit) -> 34 S.t -> 35 E.t -> 36 ctx 37 38 val fs : ctx -> Eio.Fs.dir_ty Eio.Path.t 39 (** The file system capability *) 40 41 val state : ctx -> S.t 42 (** Return the current state of the context. *) 43 44 val sigint_set : ctx -> bool 45 (** Has the signal SIGINT been set via a trap. *) 46 47 val run : ctx Exit.t -> Ast.t -> ctx Exit.t * Ast.t list 48 (** [run ctx ast] evaluates [ast] using the initial [ctx]. *) 49 50 (** {2 Private} *) 51 52 val word_expansion : ctx -> Ast.word_cst -> ctx Exit.t * Ast.fragments list 53 (* Mostly for testing purposes, this exposes the logic for expanding words. *) 54end