Subject: | parse require without semicolon |
Date: | Mon, 29 Dec 2008 08:18:03 +1100 |
To: | bug-Module-ExtractUse [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With Module::ExtractUse 0.23 and the debian perl 5.10.0 a program
use strict;
use warnings;
use Module::ExtractUse;
my $p = Module::ExtractUse->new;
my $code = 'eval { require Foo::Bar }';
$p->extract_use (\$code);
print $p->array;
prints nothing, where I hoped it would pick out "Foo::Bar" from the
require.
Omitting a semi from a single-statement block like that (either "eval",
"do", or a leg of an "if") is reasonably natural. Perhaps something
like below for the grammar. (Or is the "eos" production the right place
for it, or both, or something? :-)
--- grammar.old 2008-12-29 08:07:04.000000000 +1100
+++ grammar 2008-12-29 08:08:06.000000000 +1100
@@ -2,7 +2,7 @@
# Rules for use
#-----------------------------------------------------------------
-token_use: /\buse\s/ use_stuff ';'
+token_use: /\buse\s/ use_stuff /[;}]/
{ $return=$item{use_stuff} }
use_stuff: (base | pragma | version | module)
@@ -23,7 +23,7 @@
# Rules for require
#-----------------------------------------------------------------
-token_require: /\brequire\s/ require_stuff ';'
+token_require: /\brequire\s/ require_stuff /[;}]/
{ $return=$item{require_stuff} }
require_stuff: (version | require_name | module)
--
For lucky best wash, use Mr Sparkle.