Re: skipping backslashes at the end of lines
[email protected] ((Alexander Farber)) Mon, 31 May 2004 18:59:29 +0000
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
Please see my test case below. When I try the skip value
<skip: '(?:[ \t]|\\\n)+'> then the text parses, but the
backslashes are consumed as "value"s instead of being ignored:
$top = {
'AIF' => [
'Videorecorder.aif',
'..\\aif',
'Videorecorderaif.rss',
'\\',
'c8',
'qgn_menu_videocam_cxt.bmp',
'qgn_menu_videocam_cxt_mask.bmp',
'\\',
'qgn_menu_videocam_lst.bmp',
'"qgn_menu_videocam_lst_mask.bmp"'
]
};
I don't want to use negative look-ahead here, because the
backslashes are legal "value"s when not at the end of line.
And the <skip: '(?:[ \t]|\\[ \t]*\n)+'> doesn't parse here.
How could I skip the \ \n properly? Thank you
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: '(?:[ \t]|\\[ \t]*\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 qgn_menu_videocam_cxt.bmp qgn_menu_videocam_cxt_mask.bmp \
qgn_menu_videocam_lst.bmp "qgn_menu_videocam_lst_mask.bmp"