
Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed. The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects. Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile? Any other advice on a library to do this?

On Fri, Jul 03, 2015 at 11:26:03PM +0000, Mike Meyer wrote:
Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed.
The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects.
Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?
Any other advice on a library to do this?
Hello Mike, I am pretty sure multiple options with the same name are illegal or undefined behaviour in .ini files, so I wouldn't bet on any of the libraries supporting that. Have you thought writing your own little Parsec parser? Probably not the answer you were wishing for, but you could cannibalise this weirdly written .ini parser [1] and change the upper level functions to suit your needs.

On Fri, Jul 3, 2015 at 8:24 PM Francesco Ariis
On Fri, Jul 03, 2015 at 11:26:03PM +0000, Mike Meyer wrote:
Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed.
The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects.
Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?
Any other advice on a library to do this?
Hello Mike, I am pretty sure multiple options with the same name are illegal or undefined behaviour in .ini files, so I wouldn't bet on any of the libraries supporting that.
Is there a standard, specification or even some MS document that defines what is and is not legal? I couldn't find one. Nor do I know of any system that uses them for data interchange. Mostly they seem to be read & written solely by the program that uses them for configuration info, and edited by hand, so whatever the program accepts is legal. That's the case for the ones I'm dealing with. Since changing the program format - at least not without writing a converter - isn't an option, even having an ISO standard wouldn't matter. I've gotta deal with what we have, one way or another. Have you thought writing your own little Parsec parser? Probably not
the answer you were wishing for, but you could cannibalise this weirdly written .ini parser [1] and change the upper level functions to suit your needs.
Was there a link in there? I didn't see one. And yes, I've thought of writing my own parser for it. I figured I'd make one last check for a library before doing that. Thanks, Mike

On Sat, Jul 04, 2015 at 01:41:16AM +0000, Mike Meyer wrote:
Have you thought writing your own little Parsec parser? Probably not
the answer you were wishing for, but you could cannibalise this weirdly written .ini parser [1] and change the upper level functions to suit your needs.
Was there a link in there? I didn't see one. And yes, I've thought of writing my own parser for it. I figured I'd make one last check for a library before doing that.
Meh, silly me, here's the link http://codereview.stackexchange.com/questions/2253/ini-file-parser-in-haskel...

Maybe you can get some inspiration form the uu-options package. It uses the interleaved parsers from uu-parsinglib/uu-interleaved and easily handles options which are “distributed” over a several individual entries. It is directed towards command line options, but changing it so it works for similar formats should not be a problem.
The included Demo file shows its capabilities, and the error messages you get in case the input is incorrect. Note how the various integers are collected automatically, and how the order of the fileds in the input does not matter either,
Doaitse
data Prefers = Agda | Haskell deriving Show
<> <>data Address = Address { city_ :: String
<> , street_ :: String}
<> deriving Show
<> <>data Name = Name { name_:: String
<> , prefers_:: Prefers
<> , ints_ :: [Int]
<> , address_ :: Address}
<> deriving Show
<>
<>$(deriveLenses ''Name)
<>$(deriveLenses ''Address)
<>
<> <>instance ShowParserType Prefers where
<> showType p = "
On 04 Jul 2015, at 1:26 , Mike Meyer
wrote: Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed.
The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects.
Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?
Any other advice on a library to do this? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Fri, Jul 03, 2015 at 11:26:03PM +0000, Mike Meyer wrote:
Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed.
The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects.
Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?
Any other advice on a library to do this?
As the author of `hsini` I wouldn't mind if you created a bug report, explain the format you have (ideally you attach an example). Of course I can't promise any ETA, or even that it'll ever be done (you know how it's with FLOSS). I've pretty much used the "standard" described in the [INI article on Wikpedia](https://en.wikipedia.org/wiki/INI_file) and then picked the pieces I think make sense and have use for myself. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus Finagle's Fourth Law: Once a job is fouled up, anything done to improve it only makes it worse.

Done. See https://github.com/magthe/hsini/issues/16 for the issue about
duplicate names, including a sample ini file. I've also opened
https://github.com/magthe/hsini/issues/17 about spaces in option names. I
didn't try section names, but I've seen them with spaces in them as well,
where they were used for creating GUI elements.
The wiki entry does mention the use of duplicate names for creating
multi-valued options. It also mentioned duplicate section names, but not
the specific use I'm dealing with.
I suspect fixing this in any of the current packages would require a
fundamental rewrite of the packages I've looked at, as they all store
options as Maps to string values, and sections as Maps to option value
maps. They either need to store lists instead of maps, or use maps to
polymorphic values.
For the record, I also created an issue for the in package
https://github.com/chrisdone/ini/issues/6, as it just hands back an empty
config structure for the example file. Values outside of sections aren't
handled.
On Sat, Jul 4, 2015 at 11:33 AM Magnus Therning
On Fri, Jul 03, 2015 at 11:26:03PM +0000, Mike Meyer wrote:
Ok,I've looked at the packages google and hackage found (ini, hsini & ConfigFile), and can't use any of them for dealing with the ini files I'm being handed.
The problem is they all parse the config file into Maps, and that doesn't seem to be an option. I need lists, because I have multiple sections with the same name that turn into a list of objects, as well as sections that can have multiple options with the same name that turn into multiple objects.
Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?
Any other advice on a library to do this?
As the author of `hsini` I wouldn't mind if you created a bug report, explain the format you have (ideally you attach an example).
Of course I can't promise any ETA, or even that it'll ever be done (you know how it's with FLOSS).
I've pretty much used the "standard" described in the [INI article on Wikpedia](https://en.wikipedia.org/wiki/INI_file) and then picked the pieces I think make sense and have use for myself.
/M
-- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus
Finagle's Fourth Law: Once a job is fouled up, anything done to improve it only makes it worse. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (4)
-
Francesco Ariis
-
Magnus Therning
-
Mike Meyer
-
S. Doaitse Swierstra