Status of config file parser

Russ Allbery rra at stanford.edu
Mon Jun 4 13:36:10 UTC 2001


Since I've gone radio-silent for a while, I figured I should give a status
report.  I've been pretty busy, but I've also been working on the
configuration parser.  I now have pretty much all of the framework of the
parser written.  The tokenizer is complete; the parser can currently
handle the general mechanics of parsing and can parse parameter/value
pairs.

Support for groups and nested groups, list values, and inclusion of other
files isn't required to meet the INN 2.4 capability target, so although
they won't be much additional work since the tokenizer is already handling
those tokens, I'm not working on that yet.

Double-quoted strings are recognized and tokenized correctly, but none of
the backslash escape support is in there yet.  Comments are implemented
but not tested yet.  So far, only parsing and retrieval of boolean
parameter values is done, but adding strings, integers, and floats is
nearly done and won't be hard.

I've successfully parsed the following configuration file:

param1: on
param2: true
param3: yes
param4: off
param5: false
param6: no

and gotten the right results for each parameter.  I'm writing some more
sophisticated tests now, and then will work on adding additional parameter
types.  As soon as it can handle integers, reals, and strings (without
backslash escapes), I'll commit what I have so that other people can take
a look.

The parser does its own internal buffering and doesn't use either stdio or
the QIO library.  It will support lines of arbitrary length and doesn't
have a stdio requirement so it can be used arbitrarily inside innd without
worrying about file descriptor numbering.  (I was originally going to use
QIO, but then it ended up being easier to just do my own buffering; QIO
really wants to split on newlines, and newlines are just another token to
the parser.)  The parser is also fully reentrant; all the state is
encapsulated in structs that it passes around internally.

I really hope this is the last configuration parser that I have to write;
I forgot how incredibly fiddly writing parsers in C is if you want the
code to be readable after you're done.  Bleh.  Error handling is half the
code.

-- 
Russ Allbery (rra at stanford.edu)             <http://www.eyrie.org/~eagle/>


More information about the inn-workers mailing list