Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] need help with the parser
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2010-05-06 04:06:02


> What version are you using?  Boost 1.42?  1.43?  Trunk?
> This looks like it should work in 1.43, or at least the trunk, but
> there was a known bug with single element structs before that.

I am using Boost 1.42 and hence Spirit 2.2. single-elem struct is just
a coincidence my problem still appears if I use a two-elem struct
(again, the code enclosed and relevant extracts follow):

  struct Data { char val1; char val2; };
  BOOST_FUSION_ADAPT_STRUCT(Data,(char, val1)(char, val2));

  struct TestGrammar
  : qi::grammar<Iter, std::map<int,Data>(), ascii::space_type>
  {
    qi::rule<Iter, std::map<int,Data>(), ascii::space_type> list;
    qi::rule<Iter, Data(), ascii::space_type> value;

    TestGrammar() : TestGrammar::base_type(list) {
        value = qi::char_[ at_c<0>(_val) = _1 ]
>> qi::char_[ at_c<1>(_val) = _1 ];
        list = (qi::int_ >> value)[ _val[_1] = _2 ];
    }
  };

  int main( ) {
    std::string input = "2 c d";
    Iter iter = input.begin(), end = input.end();
    TestGrammar grammar;
    std::map<int,Data> map;
    bool ans = phrase_parse( iter, end, grammar, space, map );

    assert( ans );
    assert( iter == end );
    BOOST_AUTO( it, map.find(2) );
    assert( it != map.end() );
    assert( it->second.val1 == 'c' ); // FAILS!
    assert( it->second.val2 == 'd' ); // FAILS!
  }

> This is usually better to ask on the Spirit mailing list.  :)
Thanks for the advice, I will try that.

Regards,
&rzej




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net