|
Boost Users : |
Subject: [Boost-users] [Spirit/Qi/Phoenix] non compiling rules...
From: Francois Mauger (mauger_at_[hidden])
Date: 2013-12-12 08:37:11
Dear Boosters,
The following code is one of my first attempts to use Spirit/Qi.
For my education, I have tried 2 techniques to parse the simple
"aaa=131;" string.
The first one (Block A) compiles and seems to output the expected result.
The second (B) does not compile with a huge massively templatized
backtrace that I don't understand.
What is the difference between using online rules and
rule objects ? Is there a syntax error somewhere ?
I'm afraid the documentation and example are rather terse about the
syntax to be used here when coupling Qi and Phoenix...
Many thanks for your help.
best regards
frc
-- <pre> #include <iostream> #include <string> #include <vector> // - Boost/Spirit #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> int main( int argc_, char * argv_[]) { int error_code = EXIT_SUCCESS; using boost::spirit::qi::double_; using boost::spirit::qi::string; using boost::spirit::qi::lit; using boost::spirit::qi::lexeme; using boost::spirit::qi::phrase_parse; using boost::spirit::qi::_1; using boost::spirit::qi::as_string; using boost::spirit::ascii::space; using boost::spirit::ascii::char_; using boost::phoenix::ref; { // Block A /// This compiles: std::string s = "aaa=131;"; std::cout << "s: '" << s << "'" << std::endl; std::string::iterator strbegin = s.begin(); std::vector<char> vkey; std::vector<char> vvalue; bool r = phrase_parse( strbegin, s.end(), (+(char_ - '='))[boost::phoenix::ref(vkey) = boost::spirit::qi::_1 ] >> '=' >> *space >> lexeme[+(char_ - ';')][boost::phoenix::ref(vvalue) = boost::spirit::qi::_1 ], space ); if (r) { std::string key(vkey.begin(), vkey.end()); std::string value(vvalue.begin(), vvalue.end()); std::cout << "key : '" << key << "'" << std::endl; std::cout << "value : '" << value << "'" << std::endl; } } { /// Block B /// This doesn't: std::string s = "aaa=131;"; std::cout << "s: '" << s << "'" << std::endl; std::string::iterator strbegin = s.begin(); std::vector<char> vkey; std::vector<char> vvalue; boost::spirit::qi::rule<std::string::iterator> key_rule = +(char_ - '='); boost::spirit::qi::rule<std::string::iterator> value_rule = lexeme[+(char_ - ';')]; bool r = phrase_parse( strbegin, s.end(), key_rule[boost::phoenix::ref(vkey) = boost::spirit::qi::_1 ] >> '=' >> *space >> value_rule[boost::phoenix::ref(vvalue) = boost::spirit::qi::_1 ], space ); if (r) { std::string key(vkey.begin(), vkey.end()); std::string value(vvalue.begin(), vvalue.end()); std::cout << "key : '" << key << "'" << std::endl; std::cout << "value : '" << value << "'" << std::endl; } } return error_code; } </pre> -- François Mauger
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net