Boost logo

Boost :

Subject: Re: [boost] Help with boost spirit
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-10-14 09:32:49

2014-10-14 20:44 GMT+08:00 Theodore Papadopoulo <

> Hash: SHA1
> Sorry, this is probably a beginner question, but I'm stuck on it for
> quite some time.
> I'm trying to write a small string like parser in which the size of
> the string is first given. Some thing like:
> int_ >> repeat(_1)[ char_ ]
> But I cannot figure out the right way of doing this.
> The natural:
> const bool result = boost::spirit::qi::parse(it,str.end(),int_ >>
> repeat(_1)[ char_ ]);
> fails to compile (and I tried many variations of val, etc) with no
> success. If I replace _1 by 10, everything works fine.

_1 doesn't makes sense here, it's only for use in semantic action, e.g.
`int_[_a = _1]`.

Another question is that of the associated attribute. From the
> documentation, I would have expected it to be:
> typedef std::pair<int,std::vector<unsigned char>> Attribute;
> but that does not work. I have managed to work around this using a
> second rule, using an attribute std::vector<char>(int) but then again
> I do not know how to pass the parameter. 10 works but _1 does not.

perhaps you need to include the Fusion header that adapts std::pair.

> Any help will be appreciated. Some test code is attached, compile with:
> g++ -g -std=c++11 -dboost_spirit_use_phoenix_v3 Test.C. Variants are
> in comment.

A working version is attached.


Boost list run by bdawes at, gregod at, cpdaniel at, john at