awesome, thanks.2011/10/13 Littlefield, Tyler <tyler@tysdomain.com>
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?
The synthesized attribute you pass in (if any).
I'm confused here. Would someone mind explaining? I pass in menuitem() to one of the templates, but I'm not sure what that returns.
I'm not sure how to use the first. The second seems sort of easy, I would just use a function to do that, no? so:Is there a way I can push it to a queue since I'll have more?
By either auto attribute propagation or semantic action.I suggest the former if possible.
so the former would just be: pstart >> item[...]%delem >> pend;My actual parser will look something like:
pstart >> item >> *(delem >> item) >> pend;
FYI, "item >> *(delem >> item)" can be replaced with "item % delem".
awesome, thanks. I didn't know that I could use that rather than an iteratorHere 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?
const std::string &data -> char const* datastd::string::const_ iterator -> char const*data.begin() -> datadata.end() -> data + length
...and so on
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<std::string::const_ iterator, char, ascii::space_type> pstart = qi::char_('[');
qi::rule<std::string::const_ iterator, char, ascii::space_type> pend = qi::char_(']');
qi::rule<std::string::const_ iterator, char, ascii::space_type>delem = qi::char_('|');
qi::rule<std::string::const_ iterator, menuitem(), ascii::space_type>item = qi::char_("a-zA-Z0-9 -.?!$@") >> qi::char_('(') >> -qi::int_ >> qi::char_(':') >> qi::int_ >> qi::char_(')');
if (!qi::phrase_parse(it, itEnd, pstart >> item >> pend, ascii::space))
{
return false;
}
return true;
}
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- 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.