Command lines
val is_empty : t -> bool
is_empty l
is true
iff l
is an empty list of arguments.
val empty : t
empty
is an empty list of arguments.
val arg : string -> t
arg a
is the argument a
.
unstamp l
indicates that arguments l
do not influence the tool's invocation outputs. These arguments are omitted from the command line's stamp.
Derived combinators
val args : ?slip:string -> string list -> t
args ?slip l
is a command line from the list of arguments l
. If slip
is specified it is added on the command line before each element of l
.
val of_list : ?slip:string -> ('a -> string) -> 'a list -> t
of_list ?slip conv l
is args
?slip (List.map conv l)
.
val of_rev_list : ?slip:string -> ('a -> string) -> 'a list -> t
of_rev_list ?slip conv l
is args
?slip (List.rev_map conv l)
.
rev_paths ?slip ps
is of_rev_list
?slip Fpath.to_string ps
.
Tools
type tool = Fpath.t
The type for command line tools. A command line tool is represented by a file path according to the POSIX convention for exec(3)
. If it is made of a single segment, for example Fpath.v "ocaml"
, it represents a program name to be looked up via a search procedure; for example in the PATH
environment variable. If it is a file path with multiple segments (POSIX would say if they contain a slash characters) the program is the file itself.
set_tool tool l
replaces l
's first element with tool
. This is None
if l
is empty
.
Predicates
val is_singleton : t -> bool
is_singleton l
is true
iff l
has a single argument.
Converting
val fold : arg:(string -> 'a) -> unstamp:('a -> 'a) -> append:('a -> 'a -> 'a) -> empty:'a -> t -> 'a
fold ~arg ~unstamp ~append ~empty l
folds over l
's structure.
val iter_enc : arg:('a -> string -> unit) -> unstamp:('a -> unit) -> append:('a -> unit) -> empty:('a -> unit) -> 'a -> t -> unit
val to_list : t -> string list
to_list l
converts l
to a list of strings.
val to_stamp : t -> string list
to_stamp l
is the sequence of stamped arguments.
val to_list_and_stamp : t -> string list * string list
to_list_and_stamp l
is a l
as a list of strings tuppled with its stamp: the sequence of stamped arguments.
val to_string : t -> string
to_string l
converts l
to a string that can be passed to the command(3)
POSIX system call.
val of_string : string -> (t, string) Stdlib.result
of_string s
tokenizes s
into a command line. The tokens are recognized according to the token
production of the following grammar which should be mostly be compatible with POSIX shell tokenization.
white ::= ' ' | '\t' | '\n' | '\x0B' | '\x0C' | '\r' squot ::= '\'' dquot ::= '\"' bslash ::= '\\' tokens ::= white+ tokens | token tokens | ϵ token ::= ([^squot dquot white] | squoted | dquoted) token | ϵ squoted ::= squot [^squot]* squot dquoted ::= dquot (qchar | [^dquot])* dquot qchar ::= bslash (bslash | dquot | '$' | '`' | '\n')
qchar
are substitued by the byte they escape except for '\n'
which removes the backslash and newline from the byte stream. squoted
and dquoted
represent the bytes they enclose.