C
Clint Olsen
I'm using Perl 5.8.2, and I'm seeing some strange behavior from the pattern
matching engine.
Parse::Yapp is a module written to generate Perl in a yacc-like fashion.
However, I can't get the debugging version to work because it's not
correctly parsing between the markers in the file.
In debug mode, the module calls and modifies itself, uncommenting debug
blocks and then 'eval'-ing the string to produce a debug version of a
particular subroutine.
Here's the relevant section of code. The problem is the binary flip-flop
operator and the search pattern. For some reason, the search patterns are
not picking up the 'sub _Parse {' pattern seen in the next function.
What's more strange is that if I create a separate program with the while
loop shown in _DBLoad, I do in fact pick up the beginning and end of the
function.
Any suggestions?
Thanks,
-Clint
sub _DBLoad {
{
no strict 'refs';
exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
and return;
}
my($fname)=__FILE__;
my(@drv);
open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
while(<DRV>) {
/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
and do {
s/^#DBG>//;
push(@drv,$_);
}
}
close(DRV);
$drv[0]=~s/_P/_DBP/;
eval join('',@drv);
}
#Note that for loading debugging version of the driver,
#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
#So, DO NOT remove comment at end of sub !!!
sub _Parse {
my($self)=shift;
my($rules,$states,$lex,$error)
= @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
= @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
#DBG> my($debug)=$$self{DEBUG};
#DBG> my($dbgerror)=0;
#DBG> my($ShowCurToken) = sub {
#DBG> my($tok)='>';
#DBG> for (split('',$$token)) {
#DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
#DBG> ? sprintf('<%02X>',ord($_))
#DBG> : $_;
#DBG> }
#DBG> $tok.='<';
#DBG> };
$$errstatus=0;
....
matching engine.
Parse::Yapp is a module written to generate Perl in a yacc-like fashion.
However, I can't get the debugging version to work because it's not
correctly parsing between the markers in the file.
In debug mode, the module calls and modifies itself, uncommenting debug
blocks and then 'eval'-ing the string to produce a debug version of a
particular subroutine.
Here's the relevant section of code. The problem is the binary flip-flop
operator and the search pattern. For some reason, the search patterns are
not picking up the 'sub _Parse {' pattern seen in the next function.
What's more strange is that if I create a separate program with the while
loop shown in _DBLoad, I do in fact pick up the beginning and end of the
function.
Any suggestions?
Thanks,
-Clint
sub _DBLoad {
{
no strict 'refs';
exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
and return;
}
my($fname)=__FILE__;
my(@drv);
open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
while(<DRV>) {
/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
and do {
s/^#DBG>//;
push(@drv,$_);
}
}
close(DRV);
$drv[0]=~s/_P/_DBP/;
eval join('',@drv);
}
#Note that for loading debugging version of the driver,
#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
#So, DO NOT remove comment at end of sub !!!
sub _Parse {
my($self)=shift;
my($rules,$states,$lex,$error)
= @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
= @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
#DBG> my($debug)=$$self{DEBUG};
#DBG> my($dbgerror)=0;
#DBG> my($ShowCurToken) = sub {
#DBG> my($tok)='>';
#DBG> for (split('',$$token)) {
#DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
#DBG> ? sprintf('<%02X>',ord($_))
#DBG> : $_;
#DBG> }
#DBG> $tok.='<';
#DBG> };
$$errstatus=0;
....