Boost logo

Boost Users :

Subject: [Boost-users] Incorrect handling of synthesized attributes in Spirit.
From: Preeti Khurana (Preeti.Khurana_at_[hidden])
Date: 2010-09-09 00:59:26


I am trying to parse the lines ::

   10.1.1.1/32 10.10.1.1 29/nolabel
   10.7.7.7/32 150.2.2.2 nolabel/30

Which are space separated and putting them in a vector of strings ::

  sp %= lit(' ');

                   ip_address %= +char_("0-9") >> char_('.') >> +char_("0-9") >> char_('.') >> +char_("0-9") >> char_('.') >> +char_("0-9")
>> *char_("/") >> *char_("0-9");

                   data %= *sp >> ( xr_special | ip_address | +lit("/") | +char_("0-9A-Za-z()"));

                    start %= +(data ) >> *sp >> eoi;

qi::rule<Iterator, void()> sp;
qi::rule<Iterator, std::string()> ip_address;
qi::rule<Iterator, std::string()> data;
qi::rule<Iterator, test::Parsed_Rec()> start; (Parsed Rec carries a vector of strings )

Grammar is able to parse the lines but while parsing 29 in first line & 30 in last line, the attributes are incorrectly filled. The attributes are filled twice ( Debug File for this is debug_file_incorrect).

Snippet ::

  <data>
    <try> 29/nolabel</try>
    <xr_special>
      <try>29/nolabel</try>
      <fail/>
    </xr_special>
    <ip_address>
      <try>29/nolabel</try>
      <fail/>
    </ip_address>
    <success>/nolabel</success>
    <attributes>[[2, 9, 2, 9]]</attributes>
  </data>

While if I change my grammar to explicitly fill the attributes, they are filled correctly. File attached : debug_file_correct

                   data = *sp >> ( xr_special | ip_address[_val= _1] | +lit("/") | +char_("0-9A-Za-z()")[_val+= _1] );

<data>
    <try> 29/nolabel</try>
    <xr_special>
      <try>29/nolabel</try>
      <fail/>
    </xr_special>
    <ip_address>
      <try>29/nolabel</try>
      <fail/>
    </ip_address>
    <success>/nolabel</success>
    <attributes>[[2, 9]]</attributes>
  </data>

Thanks
Preeti





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