The LHS is available to an action via context variables
<http://search.cpan.org/~jkegl/Marpa-R2-3.000000/pod/Semantics.pod#Action_context>.
So you could write your own dispatcher and either make it the default
action or apply it selectively.

On Thu, Nov 26, 2015 at 10:17 AM, Ruslan Shvedov <[email protected]>
wrote:

>
>
> On Thu, Nov 26, 2015 at 7:25 PM, Cev Ing <[email protected]> wrote:
>
>> I am wondering if it is possible to define a LHS action. I mean something
>> like this:
>>
>> <create table> ::=
>>     (CREATE TABLE) identifier ('(') <table element list> (')' ';')
>>     action => ::lhs
>>
>> This should mean call the action with the name of the rule. Later on it
>> would be possible to define a default action for all rules:
>>
>> :default ::= action => ::lhs
>>
>> I also thought to define it myself, but I can not find a place where I
>> can define what gets passed to an action. I seems to me that it is always
>> the value. If I would be able to pass also the LHS to the action, I could
>> do the dispatching myself.
>>
>> Is it possible anyhow or do I have to write the action name in every rule:
>>
>> <create table> ::=
>>     (CREATE TABLE) identifier ('(') <table element list> (')' ';')
>>     action => create_table
>>
>> The reason why I want to use the 'action' attribute instead of 'bless'
>> is, that I want to build in one pass ready to use Perl objects. If I use
>> the 'bless' approach, I have two passes. The first builds a bunch of
>> blessed arrays, which define the AST and after that I have to traverse the
>> AST to build my Perl objects. When I use the actions to define the Perl
>> objects, I can avoid the AST creation and the second pass.
>>
> You can (1) bless each RHS alternative to specific packages, all of which
> must define the same action sub, e.g. doit() as in
> https://metacpan.org/pod/distribution/Marpa-R2/pod/Scanless.pod#Synopsis
> or (2) use action adverb to set the action subs explicitly and set a single
> semantics package for them as in
> https://github.com/jeffreykegler/Marpa--R2/blob/master/cpan/t/sl_gsyn.t
>
> In either case, actions subs will be called at the evaluation phase and
> their return values will be used to build the parse value without explicit
> AST traversal.
>
> Ron Savage has recently written a good article on how to use action subs
> to build parse value --
> http://savage.net.au/Ron/html/Understanding.Marpa-style.action.subs.parameters.html
>
>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "marpa parser" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "marpa parser" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to