From: Michael R. <rop...@gm...> - 2011-04-19 04:51:24
|
I am trying to extend the Mini-XML example that is in the Spirit::Qi documentation. I am having trouble with parsing elements with attributes. The grammar and the rule declarations follow. text = lexeme[+(char_ - '<') [_val += _1]]; node = (xml | text) [_val = _1]; Name = NameStartChar *(NameChar); NameStartChar = qi::char_("a-zA-Z_"); Digit = qi::char_("0-9"); NameChar = (NameStartChar | '-' | '.' | ':' | Digit); start_tag = '<' >> Name >> *(wspc >> attribute) >> -wspc >> '>'; wspc = ('\r'|'\t'|'\n'|' '); attribute = Name >> '=' >> AttValue; AttValue = "'" >> -Name >> "'"; end_tag = "</" >> string(_r1) >> '>' ; xml = start_tag [at_c<0>(_val) = _1] >> *node [push_back(at_c<1>(_val), _1)] >> end_tag(at_c<0>(_val)) ; } qi::rule<Iterator, mini_xml(), ascii::space_type> xml; qi::rule<Iterator, mini_xml_node(), ascii::space_type> node; qi::rule<Iterator, std::string(), ascii::space_type> text; qi::rule<Iterator, std::string(), ascii::space_type> start_tag; qi::rule<Iterator, void(std::string), ascii::space_type> end_tag; qi::rule<Iterator, std::string()> Name; qi::rule<Iterator, std::string()> NameStartChar; qi::rule<Iterator, std::string()> Digit; qi::rule<Iterator, std::string()> NameChar; qi::rule<Iterator, std::string()> wspc; qi::rule<Iterator, std::string()> attribute; qi::rule<Iterator, std::string()> AttValue; Thanks very much for your time, Michael. |