in reply to Positions of certain tokens in syntax tree

I'm guessing now ...

Here a "naive" approach by embedding Perl code.

When parsing a recursive syntax you are able to put a Perl code after each match pattern using (?{...}) and $^N will give you the content of this last match.

Compare this example from perlre

$_ = "The brown fox jumps over the lazy dog"; /the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i; print "color = $color, animal = $animal\n";

instead of storing the match you might concatenate it to a "result" string or print it to a channel

> and I want to change all identifiers to upper case in the text

depending on match pattern execute a uc before returning the result.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: Positions of certain tokens in syntax tree
by rubystallion (Novice) on Dec 14, 2019 at 08:43 UTC
    Hi Rolf, thanks for your reply. I've hopefully made the question clear now, let me know if you have any questions. I think your solution might work. I'm thinking how best to write the parsing regexp in a generally useful way, so that I can use it in the future for other tasks I might think about. Maybe I should both build a result string and a parse tree within the regexp's embedded code then.