Subject: | $Parse::RecDescent::skip not working as <skip: ...> |
The whole skip mechanisms has inconsistent or broken behaviour. Setting a global skip by
means of $Parse::RecDescent::skip does not seem to work, while using the '<skip: ...>'
directive does but is not allowed at the grammar-level, only at the production level. Attached
minimal test, this is what I get with 1.965001 in Linux:
$ perl prd-bug.pl
1..4
ok 1 - got a parser
ok 2 - foo_with_skip()
not ok 3 - foo() with regex $P::RD::skip
# Failed test 'foo() with regex $P::RD::skip'
# at prd-bug.pl line 34.
not ok 4 - foo() with string $P::RD::skip
# Failed test 'foo() with string $P::RD::skip'
# at prd-bug.pl line 40.
# Looks like you failed 2 tests of 4.
Subject: | prd-bug.pl |
#!/opt/perl/bin/perl
use strict;
use warnings;
use Parse::RecDescent;
use Test::More tests => 4;
my $grammar = <<'END_OF_GRAMMAR';
foo: item(s) eotext { $return = $item[1] }
foo_with_skip: <skip: qr/(?mxs: \s+ |\# .*?$)*/> item(s) eotext { $return = $item[1] }
item: name value { [ @item[1,2] ] }
name: 'whatever' | 'another'
value: /\S+/
eotext: /\s*\z/
END_OF_GRAMMAR
my $text = <<'END_OF_TEXT';
whatever value
# some spaces, newlines and a comment too!
another value
END_OF_TEXT
my $parser = Parse::RecDescent->new($grammar);
ok($parser, 'got a parser');
my $inskip = $parser->foo_with_skip($text);
ok($inskip, 'foo_with_skip()');
{
local $Parse::RecDescent::skip = qr/(?mxs: \s+ |\# .*?$)*/;
my $outskip = $parser->foo();
ok($outskip, 'foo() with regex $P::RD::skip');
}
{
local $Parse::RecDescent::skip = '(?mxs: \s+ |\# .*?$)*';
my $outskip = $parser->foo();
ok($outskip, 'foo() with string $P::RD::skip');
}