title: Boost Spirit : can't manage to have the alternative operator working as I expect
body: <p>I can not manage to have the spirit alternative parser working (or let'say do what I expect).</p>
  <p>Here is my MCVE</p>
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  
  #include &lt;boost/variant.hpp&gt;
  #include &lt;boost/spirit/include/qi_parse.hpp&gt;
  #include &lt;boost/spirit/include/qi.hpp&gt;
  
  using namespace boost::spirit;
  namespace charset = boost::spirit::qi::standard_wide;
  
  using Expr = boost::variant&lt;std::string, int &gt;;
  
  int main(int argc, char ** argv)
  {
      std::string intToParse = &quot;{int:  45}&quot;;
      std::string stringToParse = &quot;{string:  \&quot;foo\&quot;}&quot;;
  
      using It = std::string::const_iterator;
      using Sk = qi::space_type;
      qi::rule&lt;It, std::string(), Sk&gt; parseString;
      qi::rule&lt;It, int(), Sk&gt; parseInt;
      qi::rule&lt;It, std::string(),Sk&gt; string_;
      
      qi::rule&lt;It,Expr(),Sk &gt; orParse;
  
  
      string_ =
              qi::lit('&quot;')
              &gt; *(charset::char_ - '&quot;')
              &gt; '&quot;';
      
      parseString = qi::omit[  qi::string(&quot;string&quot;)] &gt;  qi::lit(':') &gt; string_;
  
      parseInt = qi::omit[ qi::string(&quot;int&quot;)] &gt; qi::lit(':') &gt; qi::uint_ ;
  
      orParse =  qi::omit[qi::lit('{')] &gt;  parseString | parseInt &gt;  '}';
      
      orParse.name_ =  &quot;alternative parser&quot;;
      parseString.name_ = &quot;string parser&quot;;
      parseInt.name_= &quot;int parser&quot;;
  
      qi::debug(orParse);
      qi::debug(parseString);
      qi::debug(parseInt);
  
      Expr res2;
      qi::phrase_parse(stringToParse.cbegin(), stringToParse.cend(), orParse, qi::space, res2);
      std::cout &lt;&lt; res2&lt;&lt; std::endl;
  
  
      Expr res;
      qi::phrase_parse(intToParse.cbegin(), intToParse.cend(), orParse, qi::space, res);
      std::cout &lt;&lt; res &lt;&lt; std::endl;
    
      return 0;
  }
  </code></pre>
  <p>When the first alternative fails, parsing stop, second rule is not attempted ! What did I get wrong ?</p>
  <p>Here is the output showing my issue , for the stringToParse , first alternative fails but then I expect int parser to be exercised which is not the case !</p>
  <pre><code>&lt;alternative parser&gt;
    &lt;try&gt;{string:  &quot;foo&quot;}&lt;/try&gt;
    &lt;string parser&gt;
      &lt;try&gt;string:  &quot;foo&quot;}&lt;/try&gt;
      &lt;success&gt;}&lt;/success&gt;
      &lt;attributes&gt;[[f, o, o]]&lt;/attributes&gt;
    &lt;/string parser&gt;
    &lt;success&gt;}&lt;/success&gt;
    &lt;attributes&gt;[[f, o, o]]&lt;/attributes&gt;
  &lt;/alternative parser&gt;
  foo
  &lt;alternative parser&gt;
    &lt;try&gt;{int:  45}&lt;/try&gt;
    &lt;string parser&gt;
      &lt;try&gt;int:  45}&lt;/try&gt;
      &lt;fail/&gt;
    &lt;/string parser&gt;
    &lt;fail/&gt;
  &lt;/alternative parser&gt;
  terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::spirit::qi::expectation_failure&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt; &gt;'
    what():  boost::spirit::qi::expectation_failure
  Aborted (core dumped)
  </code></pre>