Boost logo

Boost Users :

Subject: Re: [Boost-users] [Spirit]Kleene star with arguments having optional attributes.
From: Paul Graphov (graphov_at_[hidden])
Date: 2010-11-24 05:26:19


I've suddenly found a solution like this:
*((qi::char_ - 'p') >> qi::omit[*qi::lit('p')])

But nevertheless it is interesting for me why my first attempt was wrong
and how should I understand its behavior.

Thanks.

On 24 November 2010 13:06, Paul Graphov <graphov_at_[hidden]> wrote:

> Hello Boost Users,
>
> I'm now building configuration file parser with Boost.Spirit.
> I have a little trouble understanding how this parser builds attribute:
>
> It was supposed to parse strings throwing 'p' letter away.
>
> *((qi::char_ - 'p') | qi::lit('p'))
>
> attribute of qi::lit is Unused.
> attribute of (qi::char_ - 'p') is char.
>
> so attribute of ((qi::char_ - 'p') | qi::lit('p')) should be optional<char>
> that
> is uninitialized optional value when matched against character 'p'
>
> After applying Kleene star it should became vector<optional<char> >.
> It seems to be compatible with string (at least it compiles). But 'p'
> letters
> are not thrown away.
>
> The full example is here: http://pastebin.com/tCMw22Zy
>
> The output of that example is:
> Full parsing
> Result: "abcpppdef"
>
> Is it possible to make such a parser without using semantic actions
> like [bind(&string::append, res, _1)] or something like that, which seem
> to be less elegant solution.
>
> Thanks!
>



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