Download OCaml 4 Reference Guide

Transcript
330
| Set_string of string Pervasives.ref
Set the reference to the string argument
| Int of (int -> unit)
Call the function with an int argument
| Set_int of int Pervasives.ref
Set the reference to the int argument
| Float of (float -> unit)
Call the function with a float argument
| Set_float of float Pervasives.ref
Set the reference to the float argument
| Tuple of spec list
Take several arguments according to the spec list
| Symbol of string list * (string -> unit)
Take one of the symbols as argument and call the function with the symbol
| Rest of (string -> unit)
Stop interpreting keywords and call the function with each remaining argument
The concrete type describing the behavior associated with a keyword.
type key = string
type doc = string
type usage_msg = string
type anon_fun = string -> unit
val parse : (key * spec * doc) list -> anon_fun -> usage_msg -> unit
Arg.parse speclist anon_fun usage_msg parses the command line. speclist is a list of
triples (key, spec, doc). key is the option keyword, it must start with a '-' character.
spec gives the option type and the function to call when this option is found on the
command line. doc is a one-line description of this option. anon_fun is called on
anonymous arguments. The functions in spec and anon_fun are called in the same order as
their arguments appear on the command line.
If an error occurs, Arg.parse exits the program, after printing to standard error an error
message as follows:
• The reason for the error: unknown option, invalid or missing argument, etc.
• usage_msg
• The list of options, each followed by the corresponding doc string. Beware: options
that have an empty doc string will not be included in the list.