Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 59481
Status: resolved
Priority: 0/
Queue: Parse-RecDescent

People
Owner: Nobody in particular
Requestors: polettix [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.965001
Fixed in: (no value)



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'); }
Subject: Re: [rt.cpan.org #59481] $Parse::RecDescent::skip not working as <skip: ...>
Date: Sun, 18 Jul 2010 20:55:45 +1000
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks for the excellent bug report, Flavio. Show quoted text
> The whole skip mechanisms has inconsistent or broken behaviour. > Setting a global skip by means of $Parse::RecDescent::skip does not > seem to work,
It does work, but it's static (when the grammar object is built), not dynamic (when the parser is parsing). You can see this by changing your test script to the version attached as prd-bug_v2.pl. Show quoted text
> while using the '<skip: ...>' directive does but is not allowed at the > grammar-level, only at the production level.
The usual approach is to put the <skip:...> in the top level rule, from which it percolates down to all the subrules. However, the ideal of allowing a global <skip:...> is an excellent one. I'll add it to the ToDo list. BTW, if you do need dynamic skipping, you can put a <skip:...> in the top-level rule, with an interpolated variable, as demonstrated by the version attached as prd-bug_v3.pl. Damian

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #59481] $Parse::RecDescent::skip not working as <skip: ...>
Date: Mon, 19 Jul 2010 13:05:23 +0200
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Flavio Poletti <polettix [...] gmail.com>
Hello Damian, thank you for the explanation, it makes much more sense now. I don't know how deep this skip stuff goes into your ToDo, in the meantime I dare to attach a proposed patch to the documentation in order to explain this behaviour and share the alternatives you propose. Consider it a wanna-be-useful starting point for a documentation enhancement that needs proper English revision, possibly technical enhancements as well (the starting point, not the documentation!) and, of course, approval. Cheers, Flavio. On Sun, Jul 18, 2010 at 12:56 PM, damian@conway.org via RT < bug-Parse-RecDescent@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=59481 > > > Thanks for the excellent bug report, Flavio. >
> > The whole skip mechanisms has inconsistent or broken behaviour. > > Setting a global skip by means of $Parse::RecDescent::skip does not > > seem to work,
> > It does work, but it's static (when the grammar object is built), not > dynamic (when the parser is parsing). You can see this by changing your > test script to the version attached as prd-bug_v2.pl. > > >
> > while using the '<skip: ...>' directive does but is not allowed at the > > grammar-level, only at the production level.
> > The usual approach is to put the <skip:...> in the top level rule, from > which it percolates down to all the subrules. However, the ideal of > allowing a global <skip:...> is an excellent one. I'll add it to the > ToDo list. > > > BTW, if you do need dynamic skipping, you can put a <skip:...> in the > top-level rule, with an interpolated variable, as demonstrated by the > version attached as prd-bug_v3.pl. > > Damian > >

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #59481] $Parse::RecDescent::skip not working as <skip: ...>
Date: Tue, 20 Jul 2010 21:01:57 +1000
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks for the docpatch, Flavio. I've applied it (and edited it only very slightly). Very much appreciated! Damian
Thank you for the suggestion. I've added support for a global <skip:> directive (prior to any rules being defined) which functions similarly to setting $Parse::RecDescent::skip prior to compiling a grammar. You can see the changes in the commit below, and it will be a part of the next release. https://github.com/jtbraun/Parse-RecDescent/commit/262d361ba67e16eed08654246a931c80892f2503