On Tuesday, Jun 1, 2004 [EMAIL PROTECTED] said: > I've solved my problem by using > > <skip: '(?:\s|\\\\\\\\[ \t]*\n)+'> > > six backslashes work too: > > <skip: '(?:\s|\\\\\\[ \t]*\n)+'> > > Still I don't understand why this works this way > and there is not much to see in the RD_TRACE file > (only the debug print statements)
If you look at the trace dump, without all of these backslashes, you don't end up with the correct regular expression. I cannot explain why except in general terms. It has to do with the input parser, quoting and eval. The general thing here is that when you recurse through several levels of indirection, the quoting rules get really obscure. (Try writing a shell script which invokes a one line perl -e script which does a csh command...) My own personal solution is to watch what comes out in the trace and keep adding '\' characters until it looks correct. Also, why do you insist on skip always being there? (You keep adding '+' to the regular expression.) A (probably valid) corner case you did not code is the following: AIF Videorecorder.aif ..\aif Videorecorderaif.rss \ AIF c8 i.e. the null value for "value" as a continuation. > > -----Original Message----- > From: ext [mailto:[EMAIL PROTECTED] > > Why doesn't <skip: '(?:\s|\\\\|\n)+'> remove backslashes? > I get a backslash consumed as "value" in the script below: > > $top = { > 'AIF' => [ > 'Videorecorder.aif', > '..\\aif', > 'Videorecorderaif.rss', > '\\', # why is it here? > 'c8' > ] > }; > > I've read the continuation-character thread with Randall and > Domian in the archive (which is summarized in the P::RD::FAQ), > but still don't get it. Any hints please? > > Regards > Alex > > #!/usr/bin/perl > > use strict; > use vars qw($parser $text %top); > use Data::Dumper; > use Parse::RecDescent; > $RD_WARN = 1; > $RD_HINT = 1; > $RD_TRACE = 120; > use constant GRAMMAR => q( > > mmpfile: chunk(s) /^\Z/ > chunk: assignment | <error> > assignment: keyword <skip: '(?:\s|\\\\|\n)+'> value(s) { > my $href = \%::top; > push @{$href->{uc $item{keyword}}}, @{$item[3]}; > } > value: /"[^"]*"/ | ...!keyword /\S+/ > keyword: > /AIF\b/i > > ); > > $parser = Parse::RecDescent->new(GRAMMAR) or die 'Bad grammar'; > $text .= $_ while (<DATA>); > defined $parser->mmpfile($text) or die 'Bad text'; > print Data::Dumper->Dump([\%top], [qw(top)]); > > __DATA__ > AIF Videorecorder.aif ..\aif Videorecorderaif.rss \ > c8 -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226 -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226