Can't use Perl RE (s///) within (?{})

C

Clint O

Hi:

Unfortunately, the program I have is way too complex to post here, but
I wrote a lexical analyzer in Perl which makes heavy use of these code
blocks because it more closely approximates the behavior of lex/flex
than anything else I've found. I've tried both 5.8.7 and 5.10.0 with
varying results, and I've noticed that when I attempt to call the
regular expression engine inside I get two possible outcomes:

1) Out of memory
2) Segmentation fault

my $macro_text = qr/^(.*?[^\\]\n)
(?{
$text = $^N;

#$text_lines = $text =~ s|\\\n|\n|
gs;
@text_lines = split('\n', $text);

@r = ('MACRO_TEXT', $text, scalar
(@text_lines), 0);
})
/sx;

The following attempts to snarf arbitrary replacement text in a
textual macro up to a newline not preceded by a backslash. One of the
things I need to do is a few transformations according the user guide
like strip the backslashes out of the macro text. There are a few
others.

I've also noticed that declaring 'my' variables local to these blocks
can cause Perl segfaults etc. as well. I do realize these code blocks
are experimental, but this simplifies my life quite a bit by allowing
the inline code to make pattern specific calculations before the match
is complete.

Any suggestions you could offer would be much appreciated.

Thanks,

-Clint
 
S

sln

Hi:

Unfortunately, the program I have is way too complex to post here, but
I wrote a lexical analyzer in Perl which makes heavy use of these code
blocks because it more closely approximates the behavior of lex/flex
than anything else I've found. I've tried both 5.8.7 and 5.10.0 with
varying results, and I've noticed that when I attempt to call the
regular expression engine inside I get two possible outcomes:

1) Out of memory
2) Segmentation fault

my $macro_text = qr/^(.*?[^\\]\n)
(?{
$text = $^N;

#$text_lines = $text =~ s|\\\n|\n|
gs;
@text_lines = split('\n', $text);

@r = ('MACRO_TEXT', $text, scalar
(@text_lines), 0);
})
/sx;

The following attempts to snarf arbitrary replacement text in a
textual macro up to a newline not preceded by a backslash. One of the
things I need to do is a few transformations according the user guide
like strip the backslashes out of the macro text. There are a few
others.

I've also noticed that declaring 'my' variables local to these blocks
can cause Perl segfaults etc. as well. I do realize these code blocks
are experimental, but this simplifies my life quite a bit by allowing
the inline code to make pattern specific calculations before the match
is complete.

Any suggestions you could offer would be much appreciated.

Thanks,

-Clint

I don't think a regex in the code block is going to fly
even if doing the regex from a called sub. I think its more a problem
on the substitution side of s/// that is the problem. Some (re-eval 1) error.

sub strip_stuff {
my $text = shift;
$text =~ s/\\\n/\n/g;
return $text;
}

qr /...
(? {
$text = $^N;
#$text_lines = $text =~ s|\\\n|\n|gs;
$text = strip_stuff ($text);
...
})
/xs



Within the code block things are very quirky and limited.
For all but the simplest things, this is still part of the regular expression.
So inside a regular expression it would seem doubtfull you can have another regular
expression. Even the delemiters have to be different just to parse. Have you tried $text /= 5; ?

In my test, in the code block, my() crashed and any regular expression crashes thats for sure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top