home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / arg.mli < prev    next >
Encoding:
Text File  |  1993-09-24  |  2.0 KB  |  55 lines  |  [TEXT/MPS ]

  1. (* Parsing of command line arguments. *)
  2.  
  3. (* This module provides a general mechanism for extracting options and
  4.    arguments from the command line to the program. *)
  5. (* Syntax of command lines.
  6.     A keyword is a character string starting with a [-].
  7.     An option is a keyword alone or followed by an argument.
  8.     There are 4 types of keywords: Unit, String, Int, and Float.
  9.     Unit keywords do not take an argument.
  10.     String, Int, and Float keywords take the following word on the command line
  11.     as an argument.
  12.     Arguments not preceded by a keyword are called anonymous arguments.
  13.  
  14.     Examples ([foo] is assumed to be the command name):
  15.  
  16. -   [foo -flag           ](a unit option)
  17. -   [foo -int 1          ](an int option with argument [1])
  18. -   [foo -string foobar  ](a string option with argument ["foobar"])
  19. -   [foo -float 12.34    ](a float option with argument [12.34])
  20. -   [foo 1 2 3           ](three anonymous arguments: ["1"], ["2"], and ["3"])
  21. -   [foo 1 2 -flag 3 -string bar 4]
  22. -   [                    ](four anonymous arguments, a unit option, and
  23. -   [                    ] a string option with argument ["bar"])
  24. *)
  25.  
  26. type spec =
  27.   String of (string -> unit)
  28. | Int of (int -> unit)
  29. | Unit of (unit -> unit)
  30. | Float of (float -> unit)
  31. ;;
  32. (*
  33.     The concrete type describing the behavior associated with a keyword.
  34. *)
  35.  
  36. value parse : (string * spec) list -> (string -> unit) -> unit
  37. (*
  38.     [parse speclist anonfun]
  39.     parses the command line, calling the functions in [speclist]
  40.     whenever appropriate, and [anonfun] on anonymous arguments.
  41.     The functions are called in the same order as they appear on the command
  42.     line.
  43.     The strings in the [(string * spec) list] are keywords and must
  44.     start with a [-], else they are ignored.
  45.     For the user to be able to specify anonymous arguments starting with a
  46.     [-], include for example [("--", String anonfun)] in [speclist].
  47. *)
  48. ;;
  49. exception Bad of string
  50. (*
  51.     Functions in [speclist] or [anonfun] can raise [Bad message]
  52.     to reject invalid arguments.
  53. *)
  54. ;;
  55.