Problems with alternative in X3

Mikael Asplund <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hi!

I have an issue with alternatives that I don't understand why it's happening. I've simplified it even down to just x3::attr():s and I still get the problem.

Example here (code also supplied in attachment):

http://coliru.stacked-crooked.com/a/bdf4718cdeb2db4d

Why does the commented out version on line 57 work, and the active one on line 58-59 not work? It's an alternative of two exactly equal sequences, shouldn't that result in them joining to the attribute type as the single sequence?

Regards,
   Mikael

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
alt_bug.cpp (text/plain, 1.5 KB)
#include <iostream>
#include <string>
#include <vector>
#include <boost/spirit/home/x3.hpp>
#include <boost/optional.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

using std::string;
using std::vector;
using std::pair;

namespace x3 = boost::spirit::x3;

int parse_input(vector<string> v);

int main(int argc, const char* argv[]) {
    if (argc > 1) {
      return parse_input(vector<string>(&argv[1], &argv[argc + !argc]));
    }
    return 1;
}

struct Oper {
    int a;
    int b;
};

struct Ident {
    string ns;  
    string name;
};

struct Expr {
    int a;
    vector<Oper> b;
};

struct XXX {
    int a;
    Ident b;
    Expr c;
};

BOOST_FUSION_ADAPT_STRUCT(Oper, a, b)
BOOST_FUSION_ADAPT_STRUCT(Ident, ns, name)
BOOST_FUSION_ADAPT_STRUCT(Expr, a, b)
BOOST_FUSION_ADAPT_STRUCT(XXX, a, b, c)

int parse_input(vector<string> v) {
  std::stringstream ss;
  std::copy(v.begin(), v.end(), std::ostream_iterator<string>(ss, " "));
  string s = ss.str();
  auto iter = s.begin();
  auto end = s.end();
  XXX x;
//bool success = x3::phrase_parse(iter, end, x3::int_ > ((x3::attr(Ident{"",""}) >> x3::attr(Expr{3, {}}))) > ';', x3::space, x);
  bool success = x3::phrase_parse(iter, end, x3::int_ > ((x3::attr(Ident{"",""}) >> x3::attr(Expr{3, {}})) 
                                                        |(x3::attr(Ident{"",""}) >> x3::attr(Expr{3, {}}))) > ';', x3::space, x);
  return !success;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.