[Spirit Development] Bug using attr in variant

Robert Nelson <[email protected]> Thu, 30 Dec 2010 20:13:04 -0700
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <[email protected]>
The following rule is clearly glitch-ed:

boost::spirit::qi::rule<std::string::iterator,std::string()> rule =
((string("note") >> ":") | attr(std::string(""))) >> "note";

When I give it the input "note" the first branch (string("note") >>
":") fails because there is no ":" in the input string.  The
attr(std::string("")) should then pass the empty string as an
attribute.  It doesn't.  attr(std::string("")) passed the string
"note" to the return value.

Here is the code that illustrates the bug:


#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/qi_as.hpp>
#include <string>

int main()
{
  using namespace boost::spirit::qi;
  using namespace boost::phoenix;
  std::string input = "note";
  boost::spirit::qi::rule<std::string::iterator,std::string()> rule;
  rule %= ((string("note") >> ":") | attr(std::string(""))) >> "note";
  std::string output;
  bool passed = parse(input.begin(),input.end(),rule > eoi,output);
  assert(passed);
  std::cout<<"output: '"<<output<<"'"<<std::endl; //should be nothing
}

Thanks
--Robert Nelson

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
Spirit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
main.cpp (text/x-c++src, 696 B)
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/qi_as.hpp>
#include <string>

int main()
{
  using namespace boost::spirit::qi;
  using namespace boost::phoenix;
  std::string input = "note";
  boost::spirit::qi::rule<std::string::iterator,std::string()> rule;
  rule %= ((string("note") >> ":") | attr(std::string(""))) >> "note";
  std::string output;
  bool passed = parse(input.begin(),input.end(),rule > eoi,output);
  assert(passed);
  std::cout<<"output: '"<<output<<"'"<<std::endl; //should be nothing
}