|
Boost : |
Subject: Re: [boost] Spirit Not Parsing
From: Aston (blackapache512-ticket_at_[hidden])
Date: 2009-05-28 01:07:02
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_at_[hidden]>
To: boost_at_[hidden]
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/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk