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 <fa-ml@ariis.it> wrote:
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 = " <Agda | Haskell> " <> <> <>-- The next thing to do is to specify a initial record containing the default values: <>defaults = Name "Atze" Haskell [] <> (Address "Utrecht" <> "Princetonplein") <> <>-- Next we define the parser for the options, by specifying for each field what may be specified: <> <> <>oName = <> name `option` ("name", pString, "Name") <> <> ints `options` ("ints", pNaturalRaw, "A couple of numbers") <> <> prefers `choose` [("agda", Agda, "in case you prefer Agda") <> ,("haskell", Haskell, "in case you prefer Haskell") <> ] <> <> address `field` <> ( city `option` ("city", pString, "Home city") <> <> street `option` ("street" ,pString, "Home Street" ) <> ) <>{- <>-- | The function `main` may serve as a template for your own option handling. You can also use this module to see what the effectis of the various ways of passing options <>-- >>> ./Demo -i1 --ints 2 --street=Zandlust -a -nDoaitse -i3 --ints=4 --city=Tynaarlo <>-- Name {name_ = "Doaitse", prefers_ = Agda, ints_ = [1,2,3,4], address_ = Address {city_ = "Tynaarlo", street_ = "Zandlust"}} <>-- <>-- >>> ./Demo -i1 --ints 2 --street=Zandlust --name Doaitse -i3 --ints=4 --city=Tynaarlo <>-- --name [Char] optional Name <>-- --ints Int recurring A couple of numbers <>-- Choose at least one from( <>-- --agda required In case you prefer Agda <>-- --haskell required In case you prefer Haskell <>-- ) <>-- --city [Char] optional Home city <>-- --street [Char] optional Home Street <>-- -- <>-- -- Correcting steps: <>-- -- Inserted "-a" at position 70 expecting one of ["--agda", "--agda=", "--haskell", "--haskell=", "--ints=", "--ints", "-i", "-h", "-a"] <>-- -- Inserted "\EOT" at position 70 expecting "\EOT" <> <> <>main ::IO () <>main = do args <- getArgs <> case run defaults oName (concat (map (++ "\EOT") args)) of <> Left a -> case a of <> Succes v -> print v <> Help t -> putStrLn t <> Right errors -> putStrLn errors <> <>-- | The function `demo` can be used from within ghci: <>-} <> <>-- >>> demo ["-i2", "--street=Zandlust", "--ints=5", "-nAtze", "--city=Houten", "--agda", "-i3"] <>-- Name {name_ = "Atze", prefers_ = Agda, ints_ = [2,5,3], address_ = Address {city_ = "Houten", street_ = "Zandlust"}} <> <> <>demo :: [[Char]] -> IO () <>demo args = case run defaults oName (concat (map (++ "\EOT") args)) of <> Left a -> case a of <> Succes v -> print v <> Help t -> putStrLn t <> Right errors -> putStr errors
On 04 Jul 2015, at 1:26 , Mike Meyer <mwm@mired.org> 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 <magnus@therning.org> wrote:
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