Arg decoding with a template?

David Bolen db3l at
Tue Aug 7 07:04:16 CEST 2001

jimd at (Jim Dennis) writes:

>  Someone in this thread mentioned the convenience of '?-completion'
>  on *switches* as well as filenames.  Of course in the latest versions
>  of the popular UNIX/Linux shells there is support for "programmable 
>  completion."  However, it would be difficult to make that work with
>  arbitrary command arguments.  I suppose one could emulate it with 
>  a couple of features:

Well, in the system I've used (TOPS-20 native, or the CCMD C library
from Columbia for *nix systems), there's a fundamental difference to
how parsing is handled from something like getopt - or even readline.
Instead of handling a complete set of parse tables to a single parser
entry point, the code to handle parsing was itself broken out into
sections and dynamically executed as a line was parsed (or reparsed).
So not only could you build dynamic tables just prior to parsing
something (so you could vary the options for example), but some
automatic parsing functions would dynamically construct possible
values - such as that used for a filename.

>  	For each (known) command: 
> 		Build a list of known switches

In effect, rather than doing the above, you could set it up to only
build switch completions in a lazy fashion - only if the user started
to enter an option, or used a portion of a command that triggered a
particular set of options.  The code would be called as the parser
traversed that portion of the command line.

Now, in reality, most of the parsing functions did have pre-existing
static definitions, but they still only fed those definitions to the
parser a bit at a time, as those functions invoked the parser when
previous parsing reached them.

Definitely more work in terms of writing parsing code, but the end
result was probably the best interactive command line I can think of.

-- David
 \               David Bolen            \   E-mail: db3l at  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \

More information about the Python-list mailing list