FW: Regexp::Common::comment

2003-09-18 Thread jeff.bunds

I just discovered Regexp::Common today, and it's most excellent.  But I'm having 
trouble using $RE{ comment }{ Java }.  Apparently doing something like:

   grep /$RE{ comment }{ Java }/, ;

only catches comments of the form:

   // . . .

and misses comments of the form:

   /* . . .
  . . .
   */

Is this a bug?  Did I forget a prerequisite config thingy?  Can someone please point 
out my luser error?

Jeff

P.S.: sorry for the long disclaimer to follow . . .

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only
for the individual named.  If you are not the named addressee you
should not disseminate, distribute or copy this e-mail.  Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses.  The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission.  If
verification is required please request a hard-copy version.  This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.




Re: FW: Regexp::Common::comment

2003-09-18 Thread Joel Bernstein
On Thu, Sep 18, 2003 at 12:03:08PM -0400, [EMAIL PROTECTED] wrote:
> 
> I just discovered Regexp::Common today, and it's most excellent.  But I'm having 
> trouble using $RE{ comment }{ Java }.  Apparently doing something like:
> 
>grep /$RE{ comment }{ Java }/, ;
> 
> only catches comments of the form:
> 
>// . . .
> 
> and misses comments of the form:
> 
>/* . . .
>   . . .
>*/
> 
> Is this a bug?  Did I forget a prerequisite config thingy?  Can someone please point 
> out my luser error?

My guess is that grep() in that circumstance is reading line by line,
and you'd want to either slurp the file into a single scalar, or force
grep() to be greedy [this works with m// using the s modifier, but may
not with grep?].

I'm really not sure, tho.

Do you get any different results with:
my $entiretext = ;
grep /$RE{ comment }{ Java }/, $entiretext;

?

/joel



Re: FW: Regexp::Common::comment

2003-09-18 Thread Dave Hinton
On Thursday, September 18, 2003, at 05:03 pm, <[EMAIL PROTECTED]> 
wrote:

   grep /$RE{ comment }{ Java }/, ;
This is checking each individual line to see if it contains a comment.  
Catching multiline comments requires checking a group of lines as one.

Try something like:

my @comments;
local $_; {
local $/; # Makes the next line work :-)
$_ = ;  # Gets entire source file as a single string
}
push @comments, $1 while /^.*($RE{comment}{Java}).*$/gm;
Warning:  I have not tested this code.




Re: FW: Regexp::Common::comment

2003-09-20 Thread David Cantrell
On Thu, Sep 18, 2003 at 05:13:16PM +0100, Joel Bernstein wrote:
> On Thu, Sep 18, 2003 at 12:03:08PM -0400, [EMAIL PROTECTED] wrote:
> > I just discovered Regexp::Common today, and it's most excellent.  But I'm having 
> > trouble using $RE{ comment }{ Java }.  Apparently doing something like:
> >grep /$RE{ comment }{ Java }/, ;
> > only catches comments of the form:
> >// . . .
> > and misses comments of the form:
> >/* . . .
> >   . . .
> >*/
> > Is this a bug?  Did I forget a prerequisite config thingy?  Can someone please 
> > point out my luser error?
> Do you get any different results with:
> my $entiretext = ;
> grep /$RE{ comment }{ Java }/, $entiretext;

That will only read one line.  The original grep does indeed read all
the lines, but it reads them one by one.  You need to look at multiple
lines at once, so slurp them like so:

my $entiretext = join('', );

or

undef $/;
my $entiretext = ;

and then do the regex dance to find the comments.

-- 
David Cantrell |  Degenerate  | http://www.cantrell.org.uk/david

   "There seems to be something wrong with our ships today"
 -- Rear-admiral Sir David Beatty, on seeing the Queen Mary
and the Indefatigable destroyed at the Battle of Jutland