title: parsing interleaved lines with boost spirit
body: <p>I am new to spirit and currently trying to parse an ini like file into a struct. Creating the grammar is ok, but the mapping generation is still some kind of magic to me. The file looks like this:</p>
  
  <pre><code>[fine]
  @cmp1
  @cmp2
  muh=b
  
  [fail]
  @cmp1
  a=b
  @cmp2
  </code></pre>
  
  <p>it works as long as i have the requirements and properties ordered (section "fine") but I can't get it to work if the requirements and properties are interleaved (section "fail"). My struct definition looks like this:</p>
  
  <pre><code>typedef std::map&lt;std::string, std::string&gt; Pairs;
  struct Section
  {
      std::string name;
      std::vector&lt;std::string&gt; requirements;
      Pairs properties;
  };
  BOOST_FUSION_ADAPT_STRUCT(
      Section, 
      (std::string, name)
      (std::vector&lt;std::string&gt;, requirements)
      (Pairs, properties)
  )
  </code></pre>
  
  <p>My current grammar looks like this:</p>
  
  <pre><code>template &lt;typename Iterator, typename Skipper&gt;
  struct SectionParser : qi::grammar&lt;Iterator, Section(), Skipper&gt;
  {
      qi::rule&lt;Iterator, Section(), Skipper&gt; section;
      qi::rule&lt;Iterator, std::pair&lt;std::string, std::string&gt;(), Skipper&gt; pair;
      qi::rule&lt;Iterator, std::vector&lt;std::string&gt;()&gt; requirements;
      qi::rule&lt;Iterator, std::string()&gt; key, value, sectionIdent, name, component;
  
      SectionParser() 
          : SectionParser::base_type(section, "entity grammar")
      {
          using namespace qi;
  
          sectionIdent = *(qi::char_ - (qi::lit('[') | qi::lit(']') | qi::eol));
          name = *qi::eol &gt; qi::lit('[') &gt; sectionIdent &gt; qi::lit(']') &gt; (qi::eol | qi::eoi);         
  
          component = qi::char_('@') &gt; *(qi::char_ - (qi::eol)) &gt; (qi::eol | qi::eoi);
  
          value = *(qi::char_ - (qi::eol | qi::eoi));
          key = qi::char_("a-zA-Z_") &gt; *qi::char_("a-zA-Z_0-9");
          pair = key &gt; qi::lit('=') &gt; value &gt; (qi::eol | qi::eoi);
  
          section = name &gt;&gt; *component &gt;&gt; *pair;
      }
  };
  </code></pre>
  
  <p>Thats how I run the parser:</p>
  
  <pre><code>std::vector&lt;Section&gt; sections;
  bool ok = phrase_parse(first, last, (sectionParser % +qi::eol) &gt;&gt; *qi::eol &gt; qi::eoi, qi::blank, sections);
  </code></pre>
  
  <p>I also have the feeling that i made the line ending handling more complicated than it should be...</p>