
Hello:
I have a client I'm writing, where the server sends data to the client
to display as a menu in one instance. I wanted to use boost::spirit to
parse this out. So, here's the code.
I have three questions:
1) What can I do better/differently?
2) When I parse out my menuitem, if there's no flag, can it be set to 0
by default somehow?
3) Where is menuitem returned? Is there a way I can push it to a queue
since I'll have more? My actual parser will look something like:
pstart >> item >> *(delem >> item) >> pend;
Here is the code I have currently:
struct menuitem
{
std::string name;
int flag;
int choice;
};
BOOST_FUSION_ADAPT_STRUCT(
menuitem,
(std::string, name)
(int, flag)
(int, choice))
namespace ascii = boost::spirit::ascii;
namespace qi = boost::spirit::qi;
//I'd like to just take a char* here, since that's my payload. copying
the char* to a std::string will take extra time, is there a way to do that?
BOOL Menu::Parse(const std::string &data, int length)
{
std::string::const_iterator it, itEnd;
it = data.begin();
itEnd = data.end();
//we construct a few parsers to make things easier.
qi::rule
-qi::int_ >> qi::char_(':') >> qi::int_ >> qi::char_(')');
if (!qi::phrase_parse(it, itEnd, pstart >> item >> pend, ascii::space)) { return false; } return true; } -- Take care, Ty Web: http://tds-solutions.net The Aspen project: a light-weight barebones mud engine http://code.google.com/p/aspenmud Sent from my toaster.