Strict Permutation: Idea & Impl

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

Strict Permutation: Idea & Impl

TONGARI J
Hi all,

Referring to this:
http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-sequence/

Now I've implemented the strict_permutation via qi::strict[] modifier directive.
When you require to match all of the elements in the input in any order, this is what you want.

How it looks like:
--------------------------
strict[char_('a') ^ char_('b') ^ char_('c')]


Some notes:
---------------------------------
*Compound Attribute
a: A, b: B --> (strict[a ^ b]): tuple<A, B> // no optional<...>
...and so on

*Partial permutation will fail, but for those matched, attributes are propagated anyway.


The codes
--------------
https://github.com/jamboree/boost-jamboree-spirit/blob/master/boost/spirit/home/qi/directive/strict.hpp
https://github.com/jamboree/boost-jamboree-spirit/blob/master/boost/spirit/home/qi/operator/permutation.hpp
https://github.com/jamboree/boost-jamboree-spirit/blob/master/boost/spirit/home/qi/detail/permute_function.hpp

And the test:
https://github.com/jamboree/boost-jamboree-spirit/blob/master/libs/spirit/test/qi/strict_permutation.cpp


If the developers feel OK for it, I can try to make a patch.
As usual, any comment is welcome :-)




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

Hartmut Kaiser
> Referring to this:
> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
> sequence/
>
> Now I've implemented the strict_permutation via qi::strict[] modifier
> directive.
> When you require to match all of the elements in the input in any order,
> this is what you want.
>
> How it looks like:
> --------------------------
> strict[char_('a') ^ char_('b') ^ char_('c')]

Good move! Thanks! Please implement the relaxed[] directive as well, even if
it's just a no-op in tis case.

> Some notes:
> ---------------------------------
> *Compound Attribute
> a: A, b: B --> (strict[a ^ b]): tuple<A, B> // no optional<...> ...and so
> on
>
> *Partial permutation will fail, but for those matched, attributes are
> propagated anyway.
>
>
> The codes
> --------------
> https://github.com/jamboree/boost-jamboree-
> spirit/blob/master/boost/spirit/home/qi/directive/strict.hpp
> https://github.com/jamboree/boost-jamboree-
> spirit/blob/master/boost/spirit/home/qi/operator/permutation.hpp
> https://github.com/jamboree/boost-jamboree-
> spirit/blob/master/boost/spirit/home/qi/detail/permute_function.hpp
>
> And the test:
> https://github.com/jamboree/boost-jamboree-
> spirit/blob/master/libs/spirit/test/qi/strict_permutation.cpp
>
>
> If the developers feel OK for it, I can try to make a patch.
> As usual, any comment is welcome :-)

I will look at the code later.

Regards Hartmut
---------------
http://boost-spirit.com




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

MegaPixel
In reply to this post by TONGARI J
sounds cool ! that should resolve my problem with permutation and the fusion vector ! see how it goes
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

MegaPixel
I've got the two files that you commit for the strict stuff ! But Cannot open include file: 'boost/spirit/include/qi_strict.hpp': No such file or directory

that one is missing ... or you still have to do a patch !

On Fri, Jun 24, 2011 at 8:50 PM, MegaPixel <[hidden email]> wrote:
sounds cool ! that should resolve my problem with permutation and the fusion
vector ! see how it goes

--
View this message in context: http://boost.2283326.n4.nabble.com/Strict-Permutation-Idea-Impl-tp3623152p3623296.html
Sent from the spirit-general mailing list archive at Nabble.com.

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

Joel de Guzman-2
In reply to this post by Hartmut Kaiser
On 6/25/2011 2:42 AM, Hartmut Kaiser wrote:

>> Referring to this:
>> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
>> sequence/
>>
>> Now I've implemented the strict_permutation via qi::strict[] modifier
>> directive.
>> When you require to match all of the elements in the input in any order,
>> this is what you want.
>>
>> How it looks like:
>> --------------------------
>> strict[char_('a') ^ char_('b') ^ char_('c')]
>
> Good move! Thanks! Please implement the relaxed[] directive as well, even if
> it's just a no-op in tis case.

Second. Just make sure that this only works with permutations ops,
otherwise there will be confusion.

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




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
In reply to this post by MegaPixel
2011/6/25 Fabio Suriano <[hidden email]>
I've got the two files that you commit for the strict stuff ! But Cannot open include file: 'boost/spirit/include/qi_strict.hpp': No such file or directory

that one is missing ... or you still have to do a patch !

Actually it exists already,  the files I listed above are only those of more importance that I want someone to review.

You can browse all the directories:
https://github.com/jamboree/boost-jamboree-spirit

And find what is missing for you, or get the whole directory (you'll get other stuff as well...)




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
In reply to this post by Joel de Guzman-2
2011/6/25 Joel de Guzman <[hidden email]>
On 6/25/2011 2:42 AM, Hartmut Kaiser wrote:
>> Referring to this:
>> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
>> sequence/
>>
>> Now I've implemented the strict_permutation via qi::strict[] modifier
>> directive.
>> When you require to match all of the elements in the input in any order,
>> this is what you want.
>>
>> How it looks like:
>> --------------------------
>> strict[char_('a') ^ char_('b') ^ char_('c')]
>
> Good move! Thanks! Please implement the relaxed[] directive as well, even if
> it's just a no-op in tis case.

Second. Just make sure that this only works with permutations ops,
otherwise there will be confusion.

Could you elaborate the problem?
I'll investigate, but I think I'll be late this night.

Thanks.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
In reply to this post by Hartmut Kaiser
2011/6/25 Hartmut Kaiser <[hidden email]>
> Referring to this:
> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
> sequence/
>
> Now I've implemented the strict_permutation via qi::strict[] modifier
> directive.
> When you require to match all of the elements in the input in any order,
> this is what you want.
>
> How it looks like:
> --------------------------
> strict[char_('a') ^ char_('b') ^ char_('c')]

Good move! Thanks! Please implement the relaxed[] directive as well, even if
it's just a no-op in tis case.

Hi Hartmut, to implement relaxed[] as well, I think it'd be adapting what karma/strict_relaxed.hpp does to Qi, but compound_modifier specializations for tag::strict & tag::relaxed are not distinguished by the domain, so I can't make a direct adaption for Qi, do you have any suggestion? maybe moving this into a common header?

And IIUC, relaxed[] in other cases is no-op as well, so perhaps I misunderstand what the no-op is here?
I think "relaxed[strict[ a ^ b]]" should then be non-strict, correct? Or do you mean that it should be strict by no-op?


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

Joel de Guzman-2
In reply to this post by TONGARI J
On 6/25/2011 11:13 AM, TONGARI wrote:

> 2011/6/25 Joel de Guzman <[hidden email] <mailto:[hidden email]>>
>
>     On 6/25/2011 2:42 AM, Hartmut Kaiser wrote:
>     >> Referring to this:
>     >> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
>     >> sequence/
>     >>
>     >> Now I've implemented the strict_permutation via qi::strict[] modifier
>     >> directive.
>     >> When you require to match all of the elements in the input in any order,
>     >> this is what you want.
>     >>
>     >> How it looks like:
>     >> --------------------------
>     >> strict[char_('a') ^ char_('b') ^ char_('c')]
>     >
>     > Good move! Thanks! Please implement the relaxed[] directive as well, even if
>     > it's just a no-op in tis case.
>
>     Second. Just make sure that this only works with permutations ops,
>     otherwise there will be confusion.
>
>
> Could you elaborate the problem?
> I'll investigate, but I think I'll be late this night.

What happens if one writes:

    strict[ a | b | c ]

?

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




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J


2011/6/26 Joel de Guzman <[hidden email]>
On 6/25/2011 11:13 AM, TONGARI wrote:
> 2011/6/25 Joel de Guzman <[hidden email] <mailto:[hidden email]>>
>
>     On 6/25/2011 2:42 AM, Hartmut Kaiser wrote:
>     >> Referring to this:
>     >> http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-
>     >> sequence/
>     >>
>     >> Now I've implemented the strict_permutation via qi::strict[] modifier
>     >> directive.
>     >> When you require to match all of the elements in the input in any order,
>     >> this is what you want.
>     >>
>     >> How it looks like:
>     >> --------------------------
>     >> strict[char_('a') ^ char_('b') ^ char_('c')]
>     >
>     > Good move! Thanks! Please implement the relaxed[] directive as well, even if
>     > it's just a no-op in tis case.
>
>     Second. Just make sure that this only works with permutations ops,
>     otherwise there will be confusion.
>
>
> Could you elaborate the problem?
> I'll investigate, but I think I'll be late this night.

What happens if one writes:

   strict[ a | b | c ]

?

No effect.
Should I make it fail to compile instead?



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
2011/6/26 TONGARI <[hidden email]>

2011/6/26 Joel de Guzman <[hidden email]>
What happens if one writes:

   strict[ a | b | c ]

?

No effect.
Should I make it fail to compile instead?

I don't think so, and you probably not neither.
strict-relaxed is based on modifier mechanism which does not provide a way to force any restriction on its subject, does it?

Another is example is no_case, for char & string parsers, but for others it has no effect.
Correct me if I'm wrong.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

Joel de Guzman-2
On 6/26/2011 2:30 PM, TONGARI wrote:

> 2011/6/26 TONGARI <[hidden email] <mailto:[hidden email]>>
>
>
>     2011/6/26 Joel de Guzman <[hidden email] <mailto:[hidden email]>>
>
>         What happens if one writes:
>
>            strict[ a | b | c ]
>
>         ?
>
>
>     No effect.
>     Should I make it fail to compile instead?
>
>
> I don't think so, and you probably not neither.
> strict-relaxed is based on modifier mechanism which does not provide a way to force any
> restriction on its subject, does it?
>
> Another is example is no_case, for char & string parsers, but for others it has no effect.
> Correct me if I'm wrong.

You are right. Let's just leave it as-is. Other parsers may find a
use for it.

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




------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
2011/6/27 Joel de Guzman <[hidden email]>
On 6/26/2011 2:30 PM, TONGARI wrote:
> 2011/6/26 TONGARI <[hidden email] <mailto:[hidden email]>>
>
>
>     2011/6/26 Joel de Guzman <[hidden email] <mailto:[hidden email]>>
>
>         What happens if one writes:
>
>            strict[ a | b | c ]
>
>         ?
>
>
>     No effect.
>     Should I make it fail to compile instead?
>
>
> I don't think so, and you probably not neither.
> strict-relaxed is based on modifier mechanism which does not provide a way to force any
> restriction on its subject, does it?
>
> Another is example is no_case, for char & string parsers, but for others it has no effect.
> Correct me if I'm wrong.

You are right. Let's just leave it as-is. Other parsers may find a
use for it.

Well, I found more things to consider...

Suppose now we have operator @ that supports strict mode.

     strict[a @ (b ^ c)]

What if the user only wants @ to be strict but not ^ ? May be:

     strict[a @ relaxed[b ^ c]]

relaxed seems to rescue, but the logic must be different from Karma, that is:

     strict[relaxed[A]] -> A is strict in Karma; non-strict in Qi
     relaxed[strict[A]] -> A is non-strict in Karma; strict in Qi

strict-relaxed in Karma seems to have a consistent meaning, while I just picked up the keywords there, the usage is very different...

If I'm going to implement the logic for Qi, I have to modify at least:

*karma/strict_relaxed.hpp
*support/common_terminals.hpp
-> put strict/relaxed in domain specific namespaces

*support/modify.hpp
-> add member types to compound_modifier for deciding the nearest modifier is strict or relaxed

How do you think?

Maybe the best solution for me is rolling back to the operator approach to free me from the hazard :-/

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Strict Permutation: Idea & Impl

TONGARI J
2011/6/27 TONGARI <[hidden email]>
2011/6/27 Joel de Guzman <[hidden email]>
On 6/26/2011 2:30 PM, TONGARI wrote:
> 2011/6/26 TONGARI <[hidden email] <mailto:[hidden email]>>
>
>
>     2011/6/26 Joel de Guzman <[hidden email] <mailto:[hidden email]>>
>
>         What happens if one writes:
>
>            strict[ a | b | c ]
>
>         ?
>
>
>     No effect.
>     Should I make it fail to compile instead?
>
>
> I don't think so, and you probably not neither.
> strict-relaxed is based on modifier mechanism which does not provide a way to force any
> restriction on its subject, does it?
>
> Another is example is no_case, for char & string parsers, but for others it has no effect.
> Correct me if I'm wrong.

You are right. Let's just leave it as-is. Other parsers may find a
use for it.

Well, I found more things to consider...

Suppose now we have operator @ that supports strict mode.

     strict[a @ (b ^ c)]

What if the user only wants @ to be strict but not ^ ? May be:

     strict[a @ relaxed[b ^ c]]

relaxed seems to rescue, but the logic must be different from Karma, that is:

     strict[relaxed[A]] -> A is strict in Karma; non-strict in Qi
     relaxed[strict[A]] -> A is non-strict in Karma; strict in Qi

strict-relaxed in Karma seems to have a consistent meaning, while I just picked up the keywords there, the usage is very different...

If I'm going to implement the logic for Qi, I have to modify at least:

*karma/strict_relaxed.hpp
*support/common_terminals.hpp
-> put strict/relaxed in domain specific namespaces

*support/modify.hpp
-> add member types to compound_modifier for deciding the nearest modifier is strict or relaxed

How do you think?

Maybe the best solution for me is rolling back to the operator approach to free me from the hazard :-/

Hi guys, I'm stuck.

It turns out that I can't put those tags in namespace boost::spirit::qi and boost::spirit::karma, since then tag::xxx won't be found correctly where it lives.

It's necessary to separate the logic for Qi & Karma, so different tags are needed.
What do you suggest to do?



------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general