Boost logo

Boost :

Subject: [boost] Spirit Not Parsing
From: Aston (blackapache512-ticket_at_[hidden])
Date: 2009-05-28 00:48:16


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 http://in.travel.yahoo.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk