Boost logo

Boost Users :

Subject: Re: [Boost-users] [Spirit] Qi lexeme only taking the first word
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2018-11-07 04:46:03


On Tue, Nov 6, 2018 at 10:28 PM Gavin Lambert via Boost-users
<boost-users_at_[hidden]> wrote:
>
> On 7/11/2018 15:08, Michael Powell wrote:
> >> When it matches
> >>
> >> id >> *(char_('.') >> id)
> >>
> >> this has an attribute of vector<string,vector<tuple<char,std::string>>> or something similar.
> >
> > Where are you getting that from? It makes no sense whatsoever given
> > the struct full_it_t { std::string val; }, which is similarly mapped,
> > and ruled, etc.
>
> This might be wrong, but it's how I read the docs:
>
> The output of parsing is a Fusion sequence of the attributes that were
> parsed.
>
> So the output of
>
> id >> *(char_('.') >> id)
>
> is something like (but not exactly)
>
> tuple<string>
> tuple<string, char, string>
> tuple<string, char, string, char, string>
> etc
>
> string because that's the output attribute declared for id.
> char because you've used char_ instead of using '.' by itself (otherwise
> it would just disappear).
> And the latter two can be repeated zero or more times because you've used *.
>
> When you assign this to a rule with %=, it tries to best-fit this
> against the rule's declared output attribute.
>
> full_id_t contains a single string field, so the Fusion adaptation makes
> it equivalent to tuple<string>, and apparently this results in any
> additional values being discarded, not in concatenating as you expect.
>
> You can probably use an explicit semantic action to build a single
> string instead of using %=.
>
> Or you can make full_id_t contain vector<string> as rmawatson and I
> previously suggested, which should give you all the values.
>
> Another possibility, which I can't test because coliru appears to be
> grumpy at present, is to try using:
>
> full_id %= as_string[lexeme[id >> *(char_('.') >> id)]];

This approach works for me. And remains true to the AST. +1 Thanks!

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users


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