title: best way to parse plain text file with a nested information structure
body: <p>The text file has hundreds of these entries (format is MT940 bank statement)</p>
  
  <pre><code>{1:F01AHHBCH110XXX0000000000}{2:I940X           N2}{3:{108:XBS/091502}}{4:
  :20:XBS/091202/0001
  :25:5887/507004-50
  :28C:140/1
  :60F:C0914CHF7789,
  :61:0912021202D36,80NTRFNONREF//0887-1202-29-941
  04392579-0 LUTHY + xxx, ZUR
  :86:6034?60LUTHY + xxxx, ZUR vom 01.12.09 um 16:28 Karten-Nr. 2232
  2579-0
  :62F:C091202CHF52,2
  :64:C091302CHF52,2
  -}
  </code></pre>
  
  <p>This should go into an Array of Hashes like</p>
  
  <pre><code>[{"1"=&gt;"F01AHHBCH110XXX0000000000"},
    "2"=&gt;"I940X           N2", 
     3 =&gt; {108=&gt;"XBS/091502"}
  etc.
  } ]
  </code></pre>
  
  <p>I tried it with tree top, but it seemed not to be the right way, because it's more for something you want to do calculations on, and I just want the information. </p>
  
  <pre><code>grammar Mt940
  
    rule document
      part1:string spaces [:|/] spaces part2:document 
      {
        def eval(env={})
          return part1.eval, part2.eval
        end
      }
      / string
      /  '{' spaces document spaces '}' spaces
      {
        def eval(env={})
          return [document.eval]
        end
      }
    end
  end
  </code></pre>
  
  <p>I also tried with a regular expression </p>
  
  <pre><code>matches = str.scan(/\A[{]?([0-9]+)[:]?([^}]*)[}]?\Z/i)
  </code></pre>
  
  <p>but it's difficult with recursion ...</p>
  
  <p>How can I solve this problem?</p>