This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Things I like about numbers (Re: Serious eq? bug?)


Jim Blandy <jimb@red-bean.com> writes:

> I think punning the Scheme syntax to match your command-line syntax is
> kind of fishy.  I agree that you want something designed for the
> purpose, so you can get the details just right.
> 
> Olin Shivers (author of SCSH) told me one night that he had worked out
> the Ultimate Command-Line Parser For Scheme, but I haven't seen it
> yet.

Just as another example, I've briefly looked at the STALIN/QuobiScheme
parser, and assuming I understood it correctly, it has a
define-command macro

  (define-command (name arg-specs) body)

which allows you to define commands which accept complex argument
lists.  It handles setting up the function so that it can parse its
arguments for legitimate syntaxes.  This is used to define main (which
is just handed the contents of argv as a list) can be defined like as
follows (some of the specs omitted):

  (define-command
   (main (at-most-one ("cc" cc? (cc "C-compiler" string-argument "gcc")))
         (any-number
          ("copt" copt? (copts "C-compiler-options" string-argument)))
         (at-most-one ("Or" disable-runtime-checks?))
         (at-most-one ("Ot" disable-type-checks?))
         (at-most-one ("d" d?) ("da" da?))
         (at-most-one ("s" s?) ("x" x?) ("q" q?) ("t" t?))
         (at-most-one ("b32" b32?) ("b64" b64?))
         (at-most-one ("immediate-flat" immediate-flat?)
                      ("indirect-flat" indirect-flat?)
                      ("immediate-display" immediate-display?)
                      ("indirect-display" indirect-display?)
                      ("linked" linked?))
         (at-most-one
          ("align-strings" align-strings?)
          ("do-not-align-strings" do-not-align-strings?))
         (at-most-one ("d0" p0?))
         (at-most-one ("c" disable-run-cc?))
         (required (pathname "pathname" string-argument)))

   (body...))

etc.

-- 
Rob Browning <rlb@cs.utexas.edu> PGP=E80E0D04F521A094 532B97F5D64E3930