Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 130033
Status: open
Priority: 0/
Queue: Parse-RecDescent

People
Owner: Nobody in particular
Requestors: chrispitude [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Provide a way to augment autoactions instead of replacing them
From: chrispitude [...] gmail.com
It would be very useful to define actions that *augment* autoactions instead of replacing them. One possible syntax is to allow a + to be appended or prepended to the action block. For example, <autoaction: {do_me(); 1;}> word1: m{\w+} {do_me_instead(); 1;} word2: m{\w+} +{do_me_first(); 1;} word3: m{\w+} {do_me_last(); 1;}+ I'm sure there are issues to work out, but this gives the general idea. Why is this useful? I am writing a preprocessor using PRD. I need to preserve the original input file text structure. To do this, I define an autoaction that resolves every production to its string text: <skip:""> <autoaction:{$return = ::txt(@item); 1;}> I then sprinkle preprocessor actions throughout the grammar as needed. The issue is that it becomes awkward to copy the autoaction to every such sprinkled action block, even for actions as simple as setting variables. It would be much easier to write incremental actions on top of the autoaction.
Another more self-documenting syntax (which I think I prefer now) would be to substitute the autoaction for a magic keyword, *if* it exists (which maintains compatibility if it doesn't): <autoaction: {do_me(); 1;}> word1: m{\w+} {do_me_instead(); 1;} word2: m{\w+} {do_me_first(); _AUTO_; 1;} word3: m{\w+} {_AUTO_; do_me_last(); 1;}
If your proposed syntax is to add the statement "_AUTO_;" everywhere, that's not so very different from adding a call to to your do_me() sub everywhere in the first place. Replace "do_me()" with your sub named "_AUTO_()" and then the intent is even clearer, with no syntax change needed. The only difference is if you're existing the autoaction block to be a complicated set of statements or a call to "do_me(with,many,arguments)", which I agree becomes a bit more annoying to replicate everywhere. On Thu Jul 11 12:03:06 2019, chrispitude@gmail.com wrote: Show quoted text
> Another more self-documenting syntax (which I think I prefer now) > would be to substitute the autoaction for a magic keyword, *if* it > exists (which maintains compatibility if it doesn't): > > <autoaction: {do_me(); 1;}> > word1: m{\w+} {do_me_instead(); 1;} > word2: m{\w+} {do_me_first(); _AUTO_; 1;} > word3: m{\w+} {_AUTO_; do_me_last(); 1;}
It's not that I want to add the autoaction anywhere; it's that I'd like a convenient way to control whether (and where) the autoaction is included. My autoaction assigns $result to the flattened text of @item: <autoaction:{$return = ::txt(@item); 1;}> Sometimes I might want to replace the autoaction and assign the result differently; other times I might want to keep the autoaction and set some other local variable. This request seemed like a nice way to do that. It's certainly not difficult to include "$return = ::txt(@item);" everywhere I perform some other action, but that means I need to change the action in multiple places if it changes. It's a low priority nice-to-have, and is certainly not necessary!