2

I am using Regexp::Grammars to search and extract information from a complex textual source, but ultimately I want to also make replacements on that source. Is there a way to accomplish this either directly or indirectly using Regexp::Grammars?

For example, suppose I have the following definition:

use Regexp::Grammars;
qr {
    <[element]>*

    <rule: element> 
        <target> | <word> | <bracket>

    <rule: target> 
        <define> \( (<word>)* \)

    <token: define>
        define

    <token: word>
        \w+

    <token: bracket>
        [()]
}xm

How would I replace all <target>s with some replacement that is say a function of the <word> between the brackets?

Coder Guy
  • 1,843
  • 1
  • 15
  • 21
  • 1
    I doubt that's possible, but if you ask Damian directly I am sure we are in for a nice talk at the next Perl Conference. :) – simbabque Nov 02 '17 at 19:55
  • Would Autoactions or Parse-time data processing help? Something along the lines where the method called by target would manage the required replacement? Challenge is how to get the un-affected part of the input string to the output without too much clutter. – Stefan_E Jan 03 '18 at 13:20

0 Answers0