Re: How to force attribute propagation in x3 when using semantic actions

Alberto Luaces <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Seth writes:

> On 15-12-17 16:32, Alberto Luaces wrote:
>> I tried before posting, but it makes no difference for me:
>>
>> http://coliru.stacked-crooked.com/a/b58b992c2a5df373
>
>         // Let us pretend that this parses a list and not only two entities.
>
> Pretending doesn't make compilers happy. You need something that is
> actually compatible with your attribute type.
>

I though it was: at least on the Qi documentation[1] it is said that:

A >> A → vector<A>

I will check if for x3 things are different.

>
> I'd simply parse the list...:
>
>         auto const complist_def = mycomp % ',';
>
> Then you definitely did *not* want aumatic propagation here:
>
>             x3::rule<class _, comptype/*, true*/>{"my comp parser"} =
>
> For the simple reason that the attributes are not compatible.
>

Great!  Now I understand that part: a tuple or a vector would be
returned instead of a "comptype" —this is why automatic propagation is
disabled with semantic actions.

Now I would question why cannot I rely on attribute automatic detection
for the list, and have to write instead

x3::rule<class _, std::vector<comptype> > const complist("complist");

It turns out that if I remove that line and its matching
BOOST_SPIRIT_DEFINE call, and then insert this parser into bigger
compositions:

    auto const complist = mycomp % ',';  //List of complex
    auto calculator = complist % ';';    //List of lists of complex

...everything works nicely, but maybe at the expense of a bigger load
for the compiler (Coliru refuses to build this version).  So maybe the
use of BOOST_SPIRIT_DEFINE has a significant build performance advantage
over "auto" parser composition.

>
> Fixed working version: http://coliru.stacked-crooked.com/a/9926cdf49ee8215b
>
> A much simpler, more idiomatic version using
> `BOOST_FUSION_ADAPT_STRUCT`:
> http://coliru.stacked-crooked.com/a/57d6b3fcd7834644

Sorry if I did not make myself clear; this is what I did from the
beginning, and indeed it worked, but I moved on to simulate what would
happen if for some reason I would have to resort to semantic actions in
a small part of the parser.


Footnotes: 
[1]  http://www.boost.org/doc/libs/1_65_1/libs/spirit/doc/html/spirit/qi/quick_reference/compound_attribute_rules.html

-- 
Alberto


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.