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.