Different configs parser tool or library

I'm looking for tool, which can parse different config files formats from base and ports (all or at least some of those .conf, .ini, .xml etc. files), provide them as array or suchlike form, validate changes against config grammar (foo has only opinion bar, xyz is numeric, if a = b then c can be only d, e or f) and write them back to file. Optionally, any tips how to create such tool are welcome, eg. parsing, grammar specification and validation. Will be used with shell, python and php, but such bindings are not critical for this question.
 
I get the idea but the config files are pretty much all different. They may have some common ground but it will be quite difficult to parse and verify any and all config files reliably.
 
Sure, but you can have some core functionality (like read file, save file, call parse and verify etc.) and grammar specification/parsing in form of "plugins". I saw something like this implemented in C on Google code some time ago, but project was in early phase of implementation and already dead for some time, I can't recall name now.
 
Just 2 cents here: a "pluggable compiler", which if I understand correctly is basically what you're looking for, should be constructable just like any other compiler, two common tool(set)s for such a job are AntLR (primarily aimed at Java as the implementation language, contains quite a bit of O.O. clutter in my opinion) and (f)lex + yacc/bison (primarily aimed at C as the implementation language, somewhat better-known and better scalable).

The main challenge is to read "just some" input file and figure out what grammar it uses if there is no preamble or filename to reliably determine that. Perhaps you could construct a common scanner and let different parsers have a go at the token stream generated by this scanner. It would be particularly cool if these parsers can run in parallel (until one figures out that the input doesn't match its grammar, at which point it can give up) but it will be quite challenging to get this right. Another option I can think of is trying to develop some kind of pre-parser that reads the input stream and determines (either heuristically or by some more rigorous method) which grammar the file uses, if any. But it probably won't be easy to keep such a pre-parser pluggable.

In any case, it looks like you've got your work cut out for you. Good luck.

Fonz
 
You may have a look at Config::Model. It is a Perl module (a few text and graphical front-ends exist) which can read, validate and write some configuration files. However, it needs a validator specific for each config file is shall understand.
 
Back
Top