[spirit2] Containers, Tuples and Sequence attributes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[spirit2] Containers, Tuples and Sequence attributes

Joel de Guzman-2
(reposting. posted to the wrong list)

Hi,

I've been thinking about augmenting the rules for attribute
building for sequences.

(I'm using tuple<X,Y,Z> and container<T> to signify fusion
containers and stl containers respectively)

1) If the sequence a >> b has the same type for the attributes of a
    and b, it seems a good idea to allow sequences to take in an stl
    container attribute? For example:

    rule<I, std::string> r;

    r %= char_ >> char_ >> char_; // should be ok?

    In general if we have a tuple attribute tuple<T, T, T> such that
    all the attributes are of the same type, then it should also be
    compatible with container<T>. To make it more interesting, we
    can also allow compatibility of tuple<X, Y, Z> with container<T>
    as long as T is compatible with X, Y and Z.

2) Consider a very common use case:

    r %= int_ >> *(',' >> int_); // comma separated ints

    Shouldn't the attribute also be compatible with container<int> ?
    Currently, the attribute is tuple<int, container<int> >

    So in general: If we have a tuple attribute tuple<T, container<T>, T...>
    The attribute can also be compatible with container<T>.

    (**) Amending this rule should also allow the use-case presented by
    ian eyberg in his post titled "still having trouble w/basic rules"

    This one is a bit tricky to implement but I'd like to hear your
    thoughts first.

Your thoughts?

Regards,
--
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net


------------------------------------------------------------------------------
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [spirit2] Containers, Tuples and Sequence attributes

Hartmut Kaiser
> I've been thinking about augmenting the rules for attribute
> building for sequences.
>
> (I'm using tuple<X,Y,Z> and container<T> to signify fusion
> containers and stl containers respectively)
>
> 1) If the sequence a >> b has the same type for the attributes of a
>     and b, it seems a good idea to allow sequences to take in an stl
>     container attribute? For example:
>
>     rule<I, std::string> r;
>
>     r %= char_ >> char_ >> char_; // should be ok?
>
>     In general if we have a tuple attribute tuple<T, T, T> such that
>     all the attributes are of the same type, then it should also be
>     compatible with container<T>. To make it more interesting, we
>     can also allow compatibility of tuple<X, Y, Z> with container<T>
>     as long as T is compatible with X, Y and Z.
>
> 2) Consider a very common use case:
>
>     r %= int_ >> *(',' >> int_); // comma separated ints
>
>     Shouldn't the attribute also be compatible with container<int> ?
>     Currently, the attribute is tuple<int, container<int> >
>
>     So in general: If we have a tuple attribute tuple<T, container<T>,
> T...>
>     The attribute can also be compatible with container<T>.
>
>     (**) Amending this rule should also allow the use-case presented by
>     ian eyberg in his post titled "still having trouble w/basic rules"
>
>     This one is a bit tricky to implement but I'd like to hear your
>     thoughts first.

I strongly support both changes! I'm not sure, though, if this is a viable
thing to do for Karma as well. For Qi this is a pure compile time change,
while for Karma this has to have a runtime component as well. Consider:

    r %= char_ << char_ << char_;

which for instance requires a std::string with at least 3 characters as its
attribute. But what happens if the std::string contains less or more
characters?

Another issue: consider container<T> as the attribute and t << *t << t as
the grammar. This won't work as the kleene eats up all the contents of the
container...

Thoughts?
Regards Hartmut






------------------------------------------------------------------------------
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [spirit2] Containers, Tuples and Sequence attributes

Joel de Guzman-2
Hartmut Kaiser wrote:
>
> I strongly support both changes! I'm not sure, though, if this is a viable
> thing to do for Karma as well. For Qi this is a pure compile time change,
> while for Karma this has to have a runtime component as well. Consider:
>
>     r %= char_ << char_ << char_;

Yeah, it will be a runtime error.

> which for instance requires a std::string with at least 3 characters as its
> attribute. But what happens if the std::string contains less or more
> characters?

Perhaps the runtime error will fail the generator?

> Another issue: consider container<T> as the attribute and t << *t << t as
> the grammar. This won't work as the kleene eats up all the contents of the
> container...

That does not work for Qi either:

    t >> *t >> t; // *t will eat everything and later fail at the trailing t.

So, in the case of Karma, if there are no more elements in the vector
and some more are requested, then just fail the generation?

Regards,
--
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net


------------------------------------------------------------------------------
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [spirit2] Containers, Tuples and Sequence attributes

OvermindDL1
On Tue, Jan 6, 2009 at 6:29 AM, Joel de Guzman
<[hidden email]> wrote:

> Hartmut Kaiser wrote:
>>
>> I strongly support both changes! I'm not sure, though, if this is a viable
>> thing to do for Karma as well. For Qi this is a pure compile time change,
>> while for Karma this has to have a runtime component as well. Consider:
>>
>>     r %= char_ << char_ << char_;
>
> Yeah, it will be a runtime error.
>
>> which for instance requires a std::string with at least 3 characters as its
>> attribute. But what happens if the std::string contains less or more
>> characters?
>
> Perhaps the runtime error will fail the generator?
>
>> Another issue: consider container<T> as the attribute and t << *t << t as
>> the grammar. This won't work as the kleene eats up all the contents of the
>> container...
>
> That does not work for Qi either:
>
>    t >> *t >> t; // *t will eat everything and later fail at the trailing t.
>
> So, in the case of Karma, if there are no more elements in the vector
> and some more are requested, then just fail the generation?
>
> Regards,
> --
> Joel de Guzman
> http://www.boostpro.com
> http://spirit.sf.net
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Spirit-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/spirit-devel
>

Well, after being sick for a while now, this is a pleasant surprise.
I am up for this by far as I can already see a way or three that I can
simplify my bigger grammar.

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel