Re: [boost] Spirit Not Parsing

ooppss...my bad mistake is in parse_conf_file() below line is incorrect, wrong grammar rule<> conf_lines = l_root | *l_params | l_end; correct line is rule<> conf_lines = l_root >> *l_params >> l_end; sorry for pollution ________________________________ From: Aston <blackapache512-ticket@yahoo.com> To: boost@lists.boost.org Sent: Thursday, 28 May, 2009 10:18:16 AM Subject: Spirit Not Parsing Hello, I am evaluating Boot.Spirit for parsing a custom format. I have presented the code below and config file as well. I expect numUsers to be 2 but it is zero, indicating that integer_action() was not call at all. I tried with assign_d as well, it also didn't help. I guess I am missing something, and I cannot figure out that since parse() returns 0. can anybody point that out ? thanks, Aston ============ src file begin ============ #include <iostream> #include <fstream> #include <string> #include <boost/spirit.hpp> using namespace boost::spirit; int numUsers = 0; void integer_action( const int& var) { numUsers = var; }; int parse_conf_file( char* buffer) { rule<> l_root = str_p("FakeRC") >> *blank_p >> *alpha_p >> eol_p; rule<> l_params = *blank_p >> *alpha_p >> *blank_p >> str_p("Integer") >> *blank_p >> *int_p[&integer_action] >> eol_p; rule<> l_end = str_p("end") >> eol_p; rule<> conf_lines = l_root | *l_params | l_end; return parse( buffer, conf_lines).full; } int main( int argc, char** argv) { std::ifstream conf(".fakerc", std::ios::binary); conf.seekg( 0, std::ios::beg); int start = conf.tellg(); conf.seekg( 0, std::ios::end); int end = conf.tellg(); int size = end - start; conf.seekg( 0, std::ios::beg); char* buffer = new char[size]; std::fill( buffer, buffer + size, 0); conf.read( buffer, size); buffer[size - 1] = 0; int err_code = parse_conf_file( buffer); std::cout << ( err_code == 0 ? "success" : "failed"); std::cout << ": " << err_code << std::endl; std::cout << "numUsers: " << numUsers << std::endl; delete[] buffer; conf.close(); return 0; } ============ src file end ============ ============ .fakerc contents ============ FakeRC FakeRC_Name Users Integer 2 end ============ end .fakerc ============ ________________________________ Explore and discover exciting holidays and getaways with Yahoo! India Travel Click here! Bollywood news, movie reviews, film trailers and more! Go to http://in.movies.yahoo.com/

On Wed, May 27, 2009 at 11:07 PM, Aston <blackapache512-ticket@yahoo.com> wrote:
/* snip */
You really should ask Spirit things on the Spirit mailing list, lot more directed answers. Also, you should try using Spirit2.1 (boost trunk), or at the very least Spirit2.0 (Boost 1.38+, maybe 1.37 too, do not remember). Classic Spirit is so much slower and not as capable now while being harder to use.
participants (2)
-
Aston
-
OvermindDL1