mini-xml
Michael Roper <[email protected]> Tue, 19 Apr 2011 14:51:17 +1000
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <[email protected]> |
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.
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev