Here I have in mind that a possible configuration is a tree of specifications, each specification has a corresponding keyword (the string) and type. Something like this:
data Select = And | Or
data ConfigTree = Node Select [ConfigTree] | Leaf (String, *)
I'm not sure how to write this properly, given that there's no "type of types", but nevermind that for the moment.
Now, given such a tree, I want to build a parser that can read a possible valid configuration; I assume I already have sub-parsers that can parse keyword/type pairs.
For instance, a possible configuration tree is:
Node And [ Leaf ("width", Double)
, Node Or [ Leaf ("height", Double) , Leaf ("aspectratio", Double)
]
which can specify the size of a rectangle. A possible configuration file would be, say:
aspectratio = 2
width = 10
(Let's assume that a configuration file is just a list of newline separated pairs, keyword = blah, where blah is something the corresponding parser for that keyword can deal with; but they can be in any order, and just have to match up with one possible "valid subset" of the tree, where a valid subset is any subset containing the top node, that contains all the children of an "and" node it contains, and say exactly one child of an "or" node it contains.)
I have no idea how to even start building such a parser. Can anyone give some tips about how to proceed, or a way to completely restructure the above ConfigTree datatype to something more amenable to parsing?