djowel / spirit_x3

Spirit X3 Experimental
147 stars 33 forks source link

phrase_parse not working with multiple attributes. #19

Open alfC opened 8 years ago

alfC commented 8 years ago

In Spirit v3 (distributed with boost 1.60) the following code doesn't compile:

double d1 = 0.0, d2 = 0.0; x3::phrase_parse(begin, end, x3::double_ >> x3::double_, x3::space, d1, d2);

The problem is passing two attribute arguments (passing only std::pair<double, double> works). As a temporary workaround I use this code:

template<class It, class Grammar, class Skipper, class T1, class... Ts, typename = typename std::enable_if<sizeof...(Ts)>=1>::type >
bool phrase_parse(It&& it1, It&& it2, Grammar&& g, Skipper&& s, T1&& t1, Ts&&... ts){
    auto v = boost::fusion::vector_tie(std::forward<T1>(t1), std::forward<Ts>(ts)...);
    return boost::spirit::x3::phrase_parse(it1, it2, g, s, v);
}
djowel commented 8 years ago

Yes, multiple attributes are not supported. Use a tuple or fusion sequence.

alfC commented 8 years ago

Ok, I was wondering if that was an oversight. I was confused because because it was supported in Qi and even appears in one of Mike Caise examples of X3 (in one slide).

Why is the multiple attr deprecated? It made the syntax and overloading too complicated? If so I think it is a good idea.

Although it would be nice to support at least in-place creation of ties, which is not allowed now.

phrase_parse( , , double_ >> double_, std::tie(a, b));

On Mon, Sep 19, 2016 at 8:50 PM, Joel de Guzman notifications@github.com wrote:

Yes, multiple attributes are not supported. Use a tuple or fusion sequence.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

djowel commented 8 years ago

x3 is meant to be as simple as possible and remove features that can be easily done by the user. That said, i'll consider a proper patch.

alfC commented 8 years ago

I think maintaining it minimal it is a good thing, and in fact it can be implemented by the user (as I tried to do). The only problem is that it is confusing as it is right now with the examples in http://ciere.com/cppnow15/x3_docs/spirit/abstracts/compound_attributes.html

djowel commented 8 years ago

Right. It is a doc bug. It seems ported from the Qi docs.

dridk commented 6 years ago

I fall into the trap ! It has not been corrected in the documentation. https://stackoverflow.com/questions/48026044/boost-spirit-x3-parser-doesnt-work-with-multiple-attribute

djowel commented 6 years ago

Sorry about that. Actually, I am considering adding this "feature" as alfC noted. Anyone, please feel free to issue a PR to finally settle this issue.