X3: How to do locals?

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

X3: How to do locals?

Mario Lang
Hi.

Maybe a stupid question, but how do locals map from Qi to X3?
I gather it must be something around with<>, but where to put the
storage, exactly?  In Qi, parsers are constructed, so they can easily
provide the storage for the local.  In X3, a grammar returns a reference
to an already constructed rule, so I wonder, how to do this?

--
CYa,
  ⡍⠁⠗⠊⠕

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

Joel de Guzman
On 5/21/15 4:10 PM, Mario Lang wrote:
> Hi.
>
> Maybe a stupid question, but how do locals map from Qi to X3?
> I gather it must be something around with<>, but where to put the
> storage, exactly?  In Qi, parsers are constructed, so they can easily
> provide the storage for the local.  In X3, a grammar returns a reference
> to an already constructed rule, so I wonder, how to do this?

Hold on. We do not have locals (and inherited attributes) yet, but
we do have something COOL in the works :-)

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


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

sehe
In reply to this post by Mario Lang
On Thu, May 21, 2015, at 10:10 AM, Mario Lang wrote:
> Hi.
>
> Maybe a stupid question, but how do locals map from Qi to X3?
> I gather it must be something around with<>, but where to put the
> storage, exactly?  In Qi, parsers are constructed, so they can easily
> provide the storage for the local.  

Except that's not how qi::locals work. Obviously, they just "describe"
the number and type of locals, and at runtime, the phoenix context is
extended with "slots" for those.

Otherwise recursive rules could never parse correctly with locals.

I suspect the same mechanics will be present in X3 though I admit I
haven't had the time to play with X3 yet


--
Seth

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

Joel de Guzman
On 5/21/15 4:38 PM, Seth wrote:

> On Thu, May 21, 2015, at 10:10 AM, Mario Lang wrote:
>> Hi.
>>
>> Maybe a stupid question, but how do locals map from Qi to X3?
>> I gather it must be something around with<>, but where to put the
>> storage, exactly?  In Qi, parsers are constructed, so they can easily
>> provide the storage for the local.
>
> Except that's not how qi::locals work. Obviously, they just "describe"
> the number and type of locals, and at runtime, the phoenix context is
> extended with "slots" for those.
>
> Otherwise recursive rules could never parse correctly with locals.
>
> I suspect the same mechanics will be present in X3 though I admit I
> haven't had the time to play with X3 yet

Erm, the "with" does exactly that (at least close to your description):
it injects a new context T in the spirit context (as opposed to the
phoenix context). That T resides in the stack and can be accessed
anywhere in the recursive descent. That mechanism is used extensively
in X3 with such things as injecting the skipper, the error handler,
the rule's attribute and soon, the locals and inherited attributes.

The only reservation in the design of locals and inherited attributes
is syntax, since X3 uses native lambda which are very verbose and ugly!
Anyway, as I said in my latest post, we do have something cool in the
works! It will be uber cool, promise!

Cheers,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

sehe


On Thu, May 21, 2015, at 10:58 AM, Joel de Guzman wrote:
> >
> > I suspect the same mechanics will be present in X3 though I admit I
> > haven't had the time to play with X3 yet
>
> Erm, the "with" does exactly that (at least close to your description):
> it injects a new context T in the spirit context

Thanks for the confirmation + precisions!


> [...] It will be uber cool, promise!

Okay then. I'll allow it :)

--
Seth


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

Mario Lang
In reply to this post by Joel de Guzman
Joel de Guzman <[hidden email]> writes:

> On 5/21/15 4:10 PM, Mario Lang wrote:
>> Hi.
>>
>> Maybe a stupid question, but how do locals map from Qi to X3?
>> I gather it must be something around with<>, but where to put the
>> storage, exactly?  In Qi, parsers are constructed, so they can easily
>> provide the storage for the local.  In X3, a grammar returns a reference
>> to an already constructed rule, so I wonder, how to do this?
>
> Hold on. We do not have locals (and inherited attributes) yet, but
> we do have something COOL in the works :-)

OK, looking forward to it.

--
CYa,
  ⡍⠁⠗⠊⠕

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3: How to do locals?

Mario Lang
In reply to this post by Joel de Guzman
Joel de Guzman <[hidden email]> writes:

> On 5/21/15 4:10 PM, Mario Lang wrote:
>> Hi.
>>
>> Maybe a stupid question, but how do locals map from Qi to X3?
>> I gather it must be something around with<>, but where to put the
>> storage, exactly?  In Qi, parsers are constructed, so they can easily
>> provide the storage for the local.  In X3, a grammar returns a reference
>> to an already constructed rule, so I wonder, how to do this?
>
> Hold on. We do not have locals (and inherited attributes) yet, but
> we do have something COOL in the works :-)

In the meantime, I figured out that there is actually a way to do locals
already.  It is, more complicated than it would need to be, though:

struct number_tag {};
rule<struct doubled_tuplet_number, unsigned> const
doubled_tuplet_number = "doubled_tuplet_number";
auto const doubled_tuplet_number_def = []{
  unsigned number;
  return with<number_tag>(number)[
      number_sign
   >> lower_number[([](auto &ctx){ get<number_tag>(ctx) = _attr(ctx); })]
   >> number_sign
   >> lower_number[
        ([](auto &ctx){ _pass(ctx) = (get<number_tag>(ctx) == _attr(ctx)); })
      ]
   >> brl(3)[([](auto &ctx){ _val(ctx) = get<number_tag>(ctx); })]
  ];
}();
BOOST_SPIRIT_DEFINE(doubled_tuplet_number)

The outer lambda is necessary to make "number" a lvalue.  The way how
x3::with currently works, it will store a rvalue argument as const in
the context.  If I use an lvalue as argument to x3::with, it will DTRT
and the local is non-const.

--
CYa,
  ⡍⠁⠗⠊⠕

------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general