qi parsers for date_time::greg_day, greg_month, greg_year

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

qi parsers for date_time::greg_day, greg_month, greg_year

MM
Hi,

I am writing a grammar day_ whose attribute is boost::gregorian::greg_day.
This type can be constructed by an unsigned integer  >=1 and <=31.
And that is context-free, ie, it does not consider the month/year.

day_'s start_ rule would be just a uint_parser<T=std::uint8_t,
radix=10, min=1, max=2>.
The semantic action associated with start_ would attempt to
phoenix::construct<greg_day>( parsedintger).
The constructor throws if an invalid integer is passed.
I would have phoenix try_/catch_ handler, and would set
pass_ to false on exception

Opinions?

MM

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

sehe
On 24-09-14 16:26, MM wrote:
The constructor throws if an invalid integer is passed.
I would have phoenix try_/catch_ handler, and would set
pass_ to false on exception
First, why the prose if the code was just as short? Code would absolutely be clearer

I'd avoid the exception (I half-remember issues surrounding that anyways):

See it Live On Coliru
    template <typename It>
        struct grammar : qi::grammar<It, Day()>
    {
        grammar() : grammar::base_type(start_)
        {
            using namespace qi;
            start_ = uint_parser<uint8_t, 10, 1, 2>() [ _pass = (_1>=1 && _1<=31) ];
        }
      private:
        qi::rule<It, Day()> start_;
    };


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
MM
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

MM
On 24 September 2014 16:18, Seth Heeren <[hidden email]> wrote:
> On 24-09-14 16:26, MM wrote:
>
> The constructor throws if an invalid integer is passed.
> I would have phoenix try_/catch_ handler, and would set
> pass_ to false on exception
>
> First, why the prose if the code was just as short? Code would absolutely be
> clearer
Indeed, only realized that after I wrote the prose:-)

> I'd avoid the exception (I half-remember issues surrounding that anyways):
>
> See it Live On Coliru
>
>     template <typename It>
>         struct grammar : qi::grammar<It, Day()>
>     {
>         grammar() : grammar::base_type(start_)
>         {
>             using namespace qi;
>             start_ = uint_parser<uint8_t, 10, 1, 2>() [ _pass = (_1>=1 &&
> _1<=31) ];
>         }
>       private:
>         qi::rule<It, Day()> start_;
>     };

Very simple indeed.
I can't compile indeed   pnx::try_   pnx::catch_all  SA
Are you saying phoenix/try has issues?

start_ = uint_parser<uint8_t, 10, 1, 2>() [ _pass = (_1>=1 && _1<=31) ];

How is it that start_'s attribute, which is Day, gets automatically constructed from the std::uint8_t, even if we don't use %= instead of = ?
I never understood the difference between the 2?
Also, if you have _val inside your SA, it overrides the no _val behaviour?

Thanks seth,
MM

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

sehe
On 24-09-14 17:35, MM wrote:
> don't use %= instead of = ?
Oops I forgot about that. It could be that the code paths are the same
for this trivial type. Actually don't know. Should have been `%=` there.
Good call.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

sehe
In reply to this post by MM
On 24-09-14 17:35, MM wrote:
Are you saying phoenix/try has issues?
I think I vaguely remember from this SO question

Don't have time to reread the comments for specifics, though. @llonesmisz might remember too

Seth

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
MM
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

MM
In reply to this post by sehe
On 24 September 2014 16:37, Seth Heeren <[hidden email]> wrote:
On 24-09-14 17:35, MM wrote:
> don't use %= instead of = ?
Oops I forgot about that. It could be that the code paths are the same
for this trivial type. Actually don't know. Should have been `%=` there.
Good call.

Right, I confirmed.
Using only = does nothing to the attribute. I had to explicitly do [   _pass = ..., _val = ....   ]
then the attribute gets assigned. In any case, I needed a pnx::if_ 
inside the semantic action to avoid construction in case of bad number, to avoid
the exception.
thanks,

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
MM
Reply | Threaded
Open this post in threaded view
|

Re: qi parsers for date_time::greg_day, greg_month, greg_year

MM
In reply to this post by sehe
On 24 September 2014 16:40, Seth Heeren <[hidden email]> wrote:
On 24-09-14 17:35, MM wrote:
Are you saying phoenix/try has issues?
I think I vaguely remember from this SO question

Don't have time to reread the comments for specifics, though. @llonesmisz might remember too

Seth

That suggestion works there perfectly, with g++ 4.8.3 / boost 1.54/ phoenix v3
thanks, especially for the extra statement post the comma!!!! 

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general