September 14, 2018 by Roberto Di Remigio and Radovan Bast

Redesigning Getkw _or_ reinventing the wheel: 0. State of affairs and requirements

This is part 0 of a series of posts on designing a general input parsing library. By general input parsing library we mean that the format of the input is not fixed by the library itself.

In this post we will cover the state of affairs and lay out in detail the requirements for our new library.

State of affairs

The Getkw library was designed with the goal of being general. The principle of operation of Getkw is:

  1. Give me an input file.
  2. I’ll parse it and check whether it’s a legal input.
  3. If it is not legal, stop.
  4. If input is legal, I’ll dump a machine-readable file to disk. The file has all possible input parameters set to a value, whether at their default value or the value passed by the user.
  5. A reader for your language of choice (currently C, C++, and Fortran) will gobble the machine-readable file et voilà you have your input parameters.

The structure of the input revolves around the concept of keywords and sections. Keywords are the basic entity, sections collect keywords, or other sections. Loosely speaking, keywords are the bottom layer, while sections can be recursive. We’ll detail this point later.

How are sanity checks performed?

Each section gets a callback function to perform checks on its contents when the section is parsed.

Strengths

Weaknesses

Requirements for a Getkw for the future

These are the requirements for the new Getkw:

  1. It has to be a lean dependency.
  2. Usable from codes in any language.
  3. The input is structured as sections and keywords.
  4. Sections can be nested.
  5. Possibility to easily bypass parsing the file. The data structure holding the parsed input data should be easily reproducible programmatically, without having to parse a file.
  6. Input parser provides a validator mode. This will just check internal consistency of the input given by the user. This is guaranteed by defining a formal grammar.
  7. Validation is possible not only within a section, but across the entire tree/dictionary/form, without too much coupling.
  8. Make the grammar customisable.
  9. Self-documenting. Adding new sections and keywords will require documentation strings to work and there has to be a tool that can parse these and output documentation in some standard format.
  10. Composable. New sections/keywords should be addable to the parsers in a decentralized manner.

Get in touch! We are Roberto Di Remigio and Radovan Bast.