[getopt-sig] Separation of mechanics from semantics
Patrick Callahan
pac1@tiac.net
Thu, 14 Feb 2002 21:53:49 -0500
If a set of command line options form a "language", Optik, as a lexical
scanner limits the language to a small number of specific forms whose
grammar can be expressed as a single simple unordered list.
Optik simply looks at the tokens in the stream of command line artifacts and
acts on each one in turn. It contains no model of sequencing or combination
for the options and simply checks to ensure that each token or sequential
pair of tokens is a word in the "language", a word being either a single
option or an option value pair.
More complex command line option models, such as the one used in tar
introduce additional layers to the specification of the command line
"language", one that cannot be expressed or processed so simply. They check
more than if the token is in the language or not. It is at this level that
checks for combinations of tokens or such requirements as "one of c, r, t, u
or x must be supplied" is done. I don't think it could be cleanly integrated
with the lower level scanning done by optik.
Any mechanism which must use a more complex model must have some sort of
underlying parsing mechanism to deal with the tokens one at a time. That
said, are there ways we could layer the more complex parsing model on optik?
What would the lexical rules of such a mechanism look like?
There's a number of challenges in devising such a mechanism:
o What kind of expression could be used to convey the rules?
o Could the basic parsing rules for optik be easily derived or would they
need to be stated separately?
o Would the mechanism be general enough to be widely useful?
o Could the mechanism be misused,?
Here's that pesky Tar example again:
> But again, this is only an example, not an argument in favor or against
> supporting required parameters or optional arguments.
>
>
>
> man tar
>
> TAR(1) System Reference Manual
> TAR(1)
>
> NAME
> tar - tape archiver
>
> SYNOPSIS
> tar [-]{crtux}[befhmopvwzHLPXZ014578] [archive] [blocksize] [-C
> directory
> ] [-s replstr ] file1 [file2...]
>
> <snip...>
>
> One of the following flags must be present:
>
> -c Create new archive, or overwrite an existing archive,
> adding the specified files to it.
>
> <snip....>
> In addition to the flags mentioned above, any of the following flags
> may
> be used:
>
> -b blocking factor
> Set blocking factor to use for the archive, tar uses
> 512
> <snip ...>