Tuple/vector collapsing problem
Mathias Gaunard <[email protected]> Fri, 21 Jan 2011 11:17:15 +0100
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <[email protected]> |
Attached is a simple testcase that demonstrates that there is a problem in tuple to vector attribute collapsing. Indeed, the value "4", albeit correctly parsed, doesn't appear in the result. The fact there is a value 0 at the end rather than nothing is another issue: attribute collapsing doesn't deal with optionals correctly. ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ Spirit-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-devel
collapsing.cpp
(text/x-c++src, 1 KB)
#include <boost/spirit/include/qi.hpp>
#include <vector>
#include <cstring>
namespace spirit = boost::spirit;
namespace qi = spirit::qi;
struct my_grammar : qi::grammar<const char*, std::vector<int>(), spirit::ascii::space_type>
{
my_grammar() : base_type(rule)
{
rule
= ( qi::lit("if") > qi::int_ > qi::int_
> *(qi::lit("elseif") > qi::int_ > qi::int_)
> -(qi::lit("else") > qi::int_)
> qi::lit("end")
)
;
}
private:
qi::rule<const char*, std::vector<int>(), spirit::ascii::space_type> rule;
};
int main()
{
const char input[] =
"if 1\n"
" 2\n"
"elseif 3\n"
" 4\n"
"end\n"
;
std::vector<int> result;
qi::phrase_parse(&input[0], input+strlen(input), my_grammar(), spirit::ascii::space, result);
for(std::vector<int>::const_iterator it = result.begin(); it != result.end(); ++it)
std::cout << *it << std::endl;
}