<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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.<div class=""><br class=""></div><div class="">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,</div><div class=""><br class=""></div><div class=""> Doaitse</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><pre class=""><span class="hs-keyword" style="color: blue;">data</span> <span class="hs-conid">Prefers</span>  <span class="hs-keyglyph" style="color: red;">=</span>  <span class="hs-conid">Agda</span> <span class="hs-keyglyph" style="color: red;">|</span> <span class="hs-conid">Haskell</span> <span class="hs-keyword" style="color: blue;">deriving</span> <span class="hs-conid">Show</span>
<a name="line-15" class=""></a><a name="Address" class=""></a><span class="hs-keyword" style="color: blue;">data</span> <span class="hs-conid">Address</span>  <span class="hs-keyglyph" style="color: red;">=</span>  <span class="hs-conid">Address</span>  <span class="hs-layout" style="color: red;">{</span>  <span class="hs-varid">city_</span> <span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-conid">String</span>
<a name="line-16" class=""></a>                          <span class="hs-layout" style="color: red;">,</span>  <span class="hs-varid">street_</span> <span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-conid">String</span><span class="hs-layout" style="color: red;">}</span> 
<a name="line-17" class=""></a>                 <span class="hs-keyword" style="color: blue;">deriving</span> <span class="hs-conid">Show</span>
<a name="line-18" class=""></a><a name="Name" class=""></a><span class="hs-keyword" style="color: blue;">data</span> <span class="hs-conid">Name</span>     <span class="hs-keyglyph" style="color: red;">=</span>  <span class="hs-conid">Name</span>  <span class="hs-layout" style="color: red;">{</span>  <span class="hs-varid">name_</span><span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-conid">String</span> 
<a name="line-19" class=""></a>                       <span class="hs-layout" style="color: red;">,</span>  <span class="hs-varid">prefers_</span><span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-conid">Prefers</span>
<a name="line-20" class=""></a>                       <span class="hs-layout" style="color: red;">,</span>  <span class="hs-varid">ints_</span> <span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-keyglyph" style="color: red;">[</span><span class="hs-conid">Int</span><span class="hs-keyglyph" style="color: red;">]</span>
<a name="line-21" class=""></a>                       <span class="hs-layout" style="color: red;">,</span>  <span class="hs-varid">address_</span> <span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-conid">Address</span><span class="hs-layout" style="color: red;">}</span> 
<a name="line-22" class=""></a>                 <span class="hs-keyword" style="color: blue;">deriving</span> <span class="hs-conid">Show</span>
<a name="line-23" class=""></a>
<a name="line-24" class=""></a><span class="hs-varop">$</span><span class="hs-layout" style="color: red;">(</span><span class="hs-varid">deriveLenses</span> <span class="hs-chr" style="color: teal;">'</span><span class="hs-chr" style="color: teal;">'</span><span class="hs-conid">Name</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-25" class=""></a><span class="hs-varop">$</span><span class="hs-layout" style="color: red;">(</span><span class="hs-varid">deriveLenses</span> <span class="hs-chr" style="color: teal;">'</span><span class="hs-chr" style="color: teal;">'</span><span class="hs-conid">Address</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-26" class=""></a>
<a name="line-27" class=""></a><a name="instance%20ShowParserType%20Prefers" class=""></a><span class="hs-keyword" style="color: blue;">instance</span> <span class="hs-conid">ShowParserType</span> <span class="hs-conid">Prefers</span> <span class="hs-keyword" style="color: blue;">where</span>
<a name="line-28" class=""></a>   <span class="hs-varid">showType</span> <span class="hs-varid">p</span> <span class="hs-keyglyph" style="color: red;">=</span> <span class="hs-str" style="color: teal;">" <Agda | Haskell> "</span>
<a name="line-29" class=""></a>
<a name="line-30" class=""></a><a name="defaults" class=""></a><span class="hs-comment" style="color: green;">-- The next thing to do is to specify a initial record containing the default values:</span>
<a name="line-31" class=""></a><span class="hs-definition">defaults</span> <span class="hs-keyglyph" style="color: red;">=</span> <span class="hs-conid">Name</span>  <span class="hs-str" style="color: teal;">"Atze"</span> <span class="hs-conid">Haskell</span> <span class="hs-conid">[]</span> 
<a name="line-32" class=""></a>                 <span class="hs-layout" style="color: red;">(</span><span class="hs-conid">Address</span>  <span class="hs-str" style="color: teal;">"Utrecht"</span> 
<a name="line-33" class=""></a>                           <span class="hs-str" style="color: teal;">"Princetonplein"</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-34" class=""></a>
<a name="line-35" class=""></a><span class="hs-comment" style="color: green;">-- Next we define the parser for the options, by specifying for each field what may be specified:</span>
<a name="line-36" class=""></a>
<a name="line-37" class=""></a><a name="oName" class=""></a><span class="hs-definition">oName</span> <span class="hs-keyglyph" style="color: red;">=</span>
<a name="line-38" class=""></a>                 <span class="hs-varid">name</span>     <span class="hs-varop">`option`</span>   <span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"name"</span><span class="hs-layout" style="color: red;">,</span>       <span class="hs-varid">pString</span><span class="hs-layout" style="color: red;">,</span>      <span class="hs-str" style="color: teal;">"Name"</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-39" class=""></a>            <span class="hs-varop"><></span>   <span class="hs-varid">ints</span>     <span class="hs-varop">`options`</span>  <span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"ints"</span><span class="hs-layout" style="color: red;">,</span>       <span class="hs-varid">pNaturalRaw</span><span class="hs-layout" style="color: red;">,</span>  <span class="hs-str" style="color: teal;">"A couple of numbers"</span><span class="hs-layout" style="color: red;">)</span> 
<a name="line-40" class=""></a>            <span class="hs-varop"><></span>   <span class="hs-varid">prefers</span>  <span class="hs-varop">`choose`</span>   <span class="hs-keyglyph" style="color: red;">[</span><span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"agda"</span><span class="hs-layout" style="color: red;">,</span>      <span class="hs-conid">Agda</span><span class="hs-layout" style="color: red;">,</span>         <span class="hs-str" style="color: teal;">"in case you prefer Agda"</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-41" class=""></a>                                     <span class="hs-layout" style="color: red;">,</span><span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"haskell"</span><span class="hs-layout" style="color: red;">,</span>   <span class="hs-conid">Haskell</span><span class="hs-layout" style="color: red;">,</span>      <span class="hs-str" style="color: teal;">"in case you prefer Haskell"</span><span class="hs-layout" style="color: red;">)</span>
<a name="line-42" class=""></a>                                     <span class="hs-keyglyph" style="color: red;">]</span> 
<a name="line-43" class=""></a>            <span class="hs-varop"><></span>   <span class="hs-varid">address</span>  <span class="hs-varop">`field`</span>
<a name="line-44" class=""></a>                           <span class="hs-layout" style="color: red;">(</span>   <span class="hs-varid">city</span>     <span class="hs-varop">`option`</span>  <span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"city"</span><span class="hs-layout" style="color: red;">,</span>   <span class="hs-varid">pString</span><span class="hs-layout" style="color: red;">,</span> <span class="hs-str" style="color: teal;">"Home city"</span><span class="hs-layout" style="color: red;">)</span>  
<a name="line-45" class=""></a>                           <span class="hs-varop"><></span>  <span class="hs-varid">street</span>   <span class="hs-varop">`option`</span>  <span class="hs-layout" style="color: red;">(</span><span class="hs-str" style="color: teal;">"street"</span> <span class="hs-layout" style="color: red;">,</span><span class="hs-varid">pString</span><span class="hs-layout" style="color: red;">,</span> <span class="hs-str" style="color: teal;">"Home Street"</span> <span class="hs-layout" style="color: red;">)</span>
<a name="line-46" class=""></a>                           <span class="hs-layout" style="color: red;">)</span>
<a name="line-47" class=""></a><span class="hs-comment" style="color: green;">{-
<a name="line-48" style="color: green;" class=""></a>-- | 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
<a name="line-49" style="color: green;" class=""></a>-- >>> ./Demo -i1 --ints 2 --street=Zandlust -a -nDoaitse -i3 --ints=4 --city=Tynaarlo
<a name="line-50" style="color: green;" class=""></a>--     Name {name_ = "Doaitse", prefers_ = Agda, ints_ = [1,2,3,4], address_ = Address {city_ = "Tynaarlo", street_ = "Zandlust"}}
<a name="line-51" style="color: green;" class=""></a>--
<a name="line-52" style="color: green;" class=""></a>-- >>> ./Demo -i1 --ints 2 --street=Zandlust --name Doaitse -i3 --ints=4 --city=Tynaarlo
<a name="line-53" style="color: green;" class=""></a>--     --name           [Char]         optional  Name
<a name="line-54" style="color: green;" class=""></a>--     --ints           Int            recurring A couple of numbers
<a name="line-55" style="color: green;" class=""></a>--     Choose at least one from(
<a name="line-56" style="color: green;" class=""></a>--     --agda                          required  In case you prefer Agda
<a name="line-57" style="color: green;" class=""></a>--     --haskell                       required  In case you prefer Haskell
<a name="line-58" style="color: green;" class=""></a>--     )
<a name="line-59" style="color: green;" class=""></a>--     --city           [Char]         optional  Home city
<a name="line-60" style="color: green;" class=""></a>--     --street         [Char]         optional  Home Street
<a name="line-61" style="color: green;" class=""></a>--     --
<a name="line-62" style="color: green;" class=""></a>--     --  Correcting steps:
<a name="line-63" style="color: green;" class=""></a>--     --    Inserted  "-a" at position 70 expecting one of ["--agda", "--agda=", "--haskell", "--haskell=", "--ints=", "--ints", "-i", "-h", "-a"]
<a name="line-64" style="color: green;" class=""></a>--     --    Inserted  "\EOT" at position 70 expecting "\EOT"
<a name="line-65" style="color: green;" class=""></a>
<a name="line-66" style="color: green;" class=""></a>
<a name="line-67" style="color: green;" class=""></a>main  ::IO ()
<a name="line-68" style="color: green;" class=""></a>main = do args  <- getArgs
<a name="line-69" style="color: green;" class=""></a>          case run  defaults oName  (concat (map  (++ "\EOT") args)) of
<a name="line-70" style="color: green;" class=""></a>            Left a        -> case a of
<a name="line-71" style="color: green;" class=""></a>                                   Succes v -> print v
<a name="line-72" style="color: green;" class=""></a>                                   Help   t -> putStrLn t
<a name="line-73" style="color: green;" class=""></a>            Right errors  -> putStrLn errors
<a name="line-74" style="color: green;" class=""></a>
<a name="line-75" style="color: green;" class=""></a>-- | The function `demo` can be used from within ghci:
<a name="line-76" style="color: green;" class=""></a>-}</span>
<a name="line-77" class=""></a>
<a name="line-78" class=""></a><span class="hs-comment" style="color: green;">-- >>> demo ["-i2", "--street=Zandlust", "--ints=5", "-nAtze", "--city=Houten", "--agda", "-i3"]</span>
<a name="line-79" class=""></a><span class="hs-comment" style="color: green;">--     Name {name_ = "Atze", prefers_ = Agda, ints_ = [2,5,3], address_ = Address {city_ = "Houten", street_ = "Zandlust"}}</span>
<a name="line-80" class=""></a> 
<a name="line-81" class=""></a><a name="demo" class=""></a><span class="hs-definition">demo</span> <span class="hs-keyglyph" style="color: red;">::</span> <span class="hs-keyglyph" style="color: red;">[</span><span class="hs-keyglyph" style="color: red;">[</span><span class="hs-conid">Char</span><span class="hs-keyglyph" style="color: red;">]</span><span class="hs-keyglyph" style="color: red;">]</span> <span class="hs-keyglyph" style="color: red;">-></span> <span class="hs-conid">IO</span> <span class="hs-conid">()</span>
<a name="line-82" class=""></a><span class="hs-definition">demo</span> <span class="hs-varid">args</span> <span class="hs-keyglyph" style="color: red;">=</span>  <span class="hs-keyword" style="color: blue;">case</span> <span class="hs-varid">run</span>  <span class="hs-varid">defaults</span> <span class="hs-varid">oName</span>  <span class="hs-layout" style="color: red;">(</span><span class="hs-varid">concat</span> <span class="hs-layout" style="color: red;">(</span><span class="hs-varid">map</span>  <span class="hs-layout" style="color: red;">(</span><span class="hs-varop">++</span> <span class="hs-str" style="color: teal;">"\EOT"</span><span class="hs-layout" style="color: red;">)</span> <span class="hs-varid">args</span><span class="hs-layout" style="color: red;">)</span><span class="hs-layout" style="color: red;">)</span> <span class="hs-keyword" style="color: blue;">of</span>
<a name="line-83" class=""></a>                  <span class="hs-conid">Left</span> <span class="hs-varid">a</span>        <span class="hs-keyglyph" style="color: red;">-></span> <span class="hs-keyword" style="color: blue;">case</span> <span class="hs-varid">a</span> <span class="hs-keyword" style="color: blue;">of</span>
<a name="line-84" class=""></a>                                   <span class="hs-conid">Succes</span> <span class="hs-varid">v</span> <span class="hs-keyglyph" style="color: red;">-></span> <span class="hs-varid">print</span> <span class="hs-varid">v</span>
<a name="line-85" class=""></a>                                   <span class="hs-conid">Help</span>   <span class="hs-varid">t</span> <span class="hs-keyglyph" style="color: red;">-></span> <span class="hs-varid">putStrLn</span> <span class="hs-varid">t</span>
<a name="line-86" class=""></a>                  <span class="hs-conid">Right</span> <span class="hs-varid">errors</span>  <span class="hs-keyglyph" style="color: red;">-></span> <span class="hs-varid">putStr</span> <span class="hs-varid">errors</span></pre><div class=""><br class=""></div></div><div class=""><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 04 Jul 2015, at 1:26 , Mike Meyer <<a href="mailto:mwm@mired.org" class="">mwm@mired.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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.<div class=""><br class="">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.</div><div class=""><br class="">Any chance I overlooked a parser? Or maybe some parsing options in ConfigFile?</div><div class=""><br class="">Any other advice on a library to do this?</div></div>
_______________________________________________<br class="">Haskell-Cafe mailing list<br class=""><a href="mailto:Haskell-Cafe@haskell.org" class="">Haskell-Cafe@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>