
Please see attached code. Why does line A compile while line B doesn't? Thanks.

Beg pardon, wrong question. Would you give me an example of a separate string id parser (like ident?) used in a comma-separated-list parser? In short, I don't know how to resolve the discrepancy in attributes. Thanks again. On 17 Mar 2010, at 12:32 PM, Igor R wrote:
Please see attached code. Why does line A compile while line B doesn't?
It looks like the attribute of the line B cannot be converted to std::string, because the attr of *(char_(',') >> id) is vector<string>. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Beg pardon, wrong question.
Would you give me an example of a separate string id parser (like ident?) used in a comma-separated-list parser? In short, I don't know how to resolve the discrepancy in attributes.
Do you mean something like this? #include <boost/spirit/home/qi.hpp> namespace ecgp { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; template <typename Iterator> struct ident : qi::grammar<Iterator, std::string(), ascii::space_type> { ident(): ident::base_type(start) { using namespace qi; start %= lexeme[('_' | alpha) >> *(digit | alpha | '_' | '-')]; } qi::rule<Iterator, std::string(), ascii::space_type> start; }; template <typename Iterator> struct idlist : qi::grammar<Iterator, std::vector<std::string>(), ascii::space_type> { ecgp::ident<Iterator> id; idlist(): idlist::base_type(start) { using namespace qi; start %= id % ','; // don't use a sequence here } qi::rule<Iterator, std::vector<std::string>(), ascii::space_type> start; }; } namespace qi = boost::spirit::qi; int main() { ecgp::idlist<std::string::const_iterator> g; std::string input("abc,def"); std::string::const_iterator begin = input.begin(); std::string::const_iterator end = input.end(); std::vector<std::string> v; qi::phrase_parse(begin, end, g, qi::ascii::space, v); BOOST_ASSERT(v.size() == 2 && v[0] == "abc" && v[1] == "def"); return 0; } Regards Hartmut --------------- Meet me at BoostCon www.boostcon.com

Please see attached code. Why does line A compile while line B doesn't? Thanks.
Here is the code (to have a reference): template <typename Iterator> struct idlist: qi::grammar<Iterator, std::string(), ascii::space_type> { ecgp::ident<Iterator> id; idlist(): idlist::base_type(start) { using namespace qi; start %= id >> (char_(',') >> id); // line A //start %= id >> *(char_(',') >> id); // line B } qi::rule<Iterator, std::string(), ascii::space_type> start; }; where the attribute of id is std::string. The problem is an attribute mismatch of the attribute exposed by start (which is std::string) and the rhs, which formally exposes tuple<std::string, std::vector<std::string>>, but in addition should be compatible with a plain std::vector<std::string> (although we know there is a bug preventing this to compile). If you are really just interested in the overall string matched by start's rhs, you could write: start %= raw[id >> *(char_(',') >> id)]; HTH Regards Hartmut --------------- Meet me at BoostCon www.boostcon.com
participants (4)
-
Hartmut Kaiser
-
Igor R
-
philip tucker
-
Steven Watanabe