|
Boost : |
Subject: [boost] [spirit][qi] strange attribute composition when using expectation points
From: Evonik Energy Services GmbH (tobias.loew_at_[hidden])
Date: 2010-09-10 03:52:48
Hi,
I get a different attribute composition depending on the use of expectation points. Here is a small example:
////////////////////////////////////////////////////////////////////////////////////////////////
//
BOOST_FUSION_DEFINE_STRUCT(
(client), input,
(int, index1)
(std::string, text)
(int, index2)
)
namespace client {
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
namespace qi = boost::spirit::qi;
namespace char_enc = boost::spirit::iso8859_1;
template <typename Iterator, typename Skipper>
struct line_grammar
: qi::grammar<Iterator, input(), Skipper>
{
line_grammar()
: line_grammar::base_type(line)
{
using qi::int_;
using qi::omit;
using char_enc::char_;
using qi::lit;
line =
int_
>> lit(",")
#ifdef USE_EXPECTATION_POINT
> *(char_ - ( "," >> int_ ) )
#else
>> *(char_ - ( "," >> int_ ) )
#endif
>> lit(",")
>> int_
;
}
qi::rule<Iterator, input(), Skipper > line;
};
bool read_line( )
{
typedef line_grammar<std::string::const_iterator, char_enc::space_type> grammar;
grammar gr; // Our grammar
input line_read;
std::string source = "1,x,2";
std::string::const_iterator iter = source.begin();
std::string::const_iterator end = source.end();
bool r = phrase_parse(iter, end, gr,
char_enc::space,
line_read);
return r && iter == end;
}
}
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
If USE_EXPECTATION_POINT is not defined then parsing succeeds and line_read == {1, "x", 2 }.
But if USE_EXPECTATION_POINT is defined then parsing also succeeds but line_read == {1, "x\0x2", 0 }.
So, it seems that expectation points somehow break the semantics of attribute composition.
Tobias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk