Command-line Parsing Combinators
Half-baked talk, February 11, 2005
by Thomas Hallgren
Abstract
The Programatica Haskell front-end (PFE) has a command line interface
that provides a lot of functionality and I have been looking for a
nice way to program it. By nice, I mean that
- It should be possible describe the command line syntax in a
modular/reusable/extensible way. PFE, like CVS, has a command line
syntax with a number of subcommands, each with its own set of
arguments and options. Other people should be able to add new subcommands
to the command line interface by adding new modules and reusing
existing modules unchanged.
- The implementation should be self-documenting, i.e., the
implementation of the command-line interface should look similar
to the user documentation.
- The documentation of the command line syntax should always be in
sync with the implementation. To ensure this, I want the command
line parser and the documentation to be generated from the same
source.
Being a functional programmer, my choice is to use parsing
combinators, since they satisfy most of the above goals. The only goal
not satisfied by available parsing combinators is the ability to
extract documentation as well as a parser from the same source, so in
the talk, I describe my own parsing combinators that solve this
problem (under some simplifying assumptions). They are currently used
in the implementation of PFE.
Thomas Hallgren