title: Boost spirit revert parsing
body: <p>I want to parse a file containing the following structure:</p>
  
  <pre><code>some
  garbage *&amp;%
  section1 {
      section_content
  }
  section2 {
      section_content
  }
  </code></pre>
  
  <p>The rule parsing <code>section_name1 { ... } section_name2 { ... }</code> is already defined:</p>
  
  <pre><code>section_name_rule = lexeme[+char_("A-Za-z0-9_")];
  section = section_name_rule &gt; lit("{") &gt; /*some complicated things*/... &gt; lit("}");
  sections %= +section;
  </code></pre>
  
  <p>So I need to skip any garbage until the <code>sections</code> rule is met.
  Is there any way to accomplish this? I have tried <code>seek[sections]</code>, but it seems not to work.</p>
  
  <p><strong>EDIT</strong>:
  I localized the reason why seek is not working: if I use follows operator(<code>&gt;&gt;</code>), then it works. If expectation parser is used (<code>&gt;</code>), then it throws an exception. Here is a sample code:</p>
  
  <pre><code>#define BOOST_SPIRIT_DEBUG
  #include &lt;boost/fusion/adapted/struct.hpp&gt;
  #include &lt;boost/spirit/include/qi.hpp&gt;
  #include &lt;boost/spirit/repository/include/qi_seek.hpp&gt;
  #include &lt;boost/spirit/include/phoenix.hpp&gt;
  
  namespace qi = boost::spirit::qi;
  using boost::phoenix::push_back;
  
  struct section_t {
      std::string name, contents;
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, section_t const&amp; s) { return os &lt;&lt; "section_t[" &lt;&lt; s.name &lt;&lt; "] {" &lt;&lt; s.contents &lt;&lt; "}"; }
  };
  
  BOOST_FUSION_ADAPT_STRUCT(section_t, (std::string, name)(std::string, contents))
  
      typedef std::vector&lt;section_t&gt; sections_t;
  
      template &lt;typename It, typename Skipper = qi::space_type&gt;
      struct grammar : qi::grammar&lt;It, sections_t(), Skipper&gt;
  {
      grammar() : grammar::base_type(start) {
          using namespace qi;
          using boost::spirit::repository::qi::seek;
          section_name_rule = lexeme[+char_("A-Za-z0-9_")];
          //Replacing '&gt;&gt;'s with '&gt;'s throws an exception, while this works as expected!!
          section = section_name_rule
              &gt;&gt;
              lit("{") &gt;&gt; lexeme[*~char_('}')] &gt;&gt; lit("}");
          start = seek [ hold[section[push_back(qi::_val, qi::_1)]] ]
              &gt;&gt; *(section[push_back(qi::_val, qi::_1)]);
      }
      private:
      qi::rule&lt;It, sections_t(),  Skipper&gt; start;
      qi::rule&lt;It, section_t(),   Skipper&gt; section;
      qi::rule&lt;It, std::string(), Skipper&gt; section_name_rule;
  };
  
  int main() {
      typedef std::string::const_iterator iter;
      std::string storage("sdfsdf\n sd:fgdfg section1 {dummy } section2 {dummy  } section3 {dummy  }");
      iter f(storage.begin()), l(storage.end());
      sections_t sections;
      if (qi::phrase_parse(f, l, grammar&lt;iter&gt;(), qi::space, sections))
      {
          for(auto&amp; s : sections)
              std::cout &lt;&lt; "Parsed: " &lt;&lt; s &lt;&lt; "\n";
      }
      if (f != l)
          std::cout &lt;&lt; "Remaining unparsed: '" &lt;&lt; std::string(f,l) &lt;&lt; "'\n";
  }
  </code></pre>
  
  <p>So in the real example my entire grammar is constructed with expectation operators. Do I have to change everything to make the "seek" work, or is there any other way (let's say, seek a simple "{", and revert one section_name_rule back)??</p>