<?xml version="1.0" encoding="windows-1252"?>
<node id="527410" title="Re: Random Tips on Parse::RecDescent" created="2006-02-02 14:39:31" updated="2006-02-02 09:39:31">
<type id="11">
note</type>
<author id="526306">
davistar</author>
<data>
<field name="doctext">
hsm,&lt;br&gt;

Thanks for the excellent tips on PRD! I'm trying to use tip #16 for C-like multiline comments '/*' and '*/'.
&lt;br&gt;
I don't quite understand your syntax for the following production:

&lt;code&gt;
xcomment:
        &amp;lt;skip: qr/[ \t]*/&amp;gt; newline(0..) '&amp;lt;!--'
        {
            ($text,$return) = main::parse_delimited($text,'&amp;lt;!--','-+-&amp;gt;');
             $return = ['xcomment',$return];
        }
&lt;/code&gt;

I translated your xcomment production into the following production:
&lt;code&gt;
comment:
        &lt;skip: qr/[ \t]*/&gt; newline(0..) '/*'
        {
            ($text,$return) = main::parse_delimited($text,'/*','*/');
             $return = ['comment',$return];
        }
&lt;/code&gt;
My question is I don't understand the newline(0..) part I must missing something obvious. I had errors if I used newline(0..) and main::parse_delimited so I removed newline(0..) and changed main:: to $thisparser-&gt; and ran the following test with no compile errors but it fails to match the comment production. What am I missing? Any help debugging would be appreciated!

&lt;code&gt;
#!/usr/bin/perl -w
use strict;
use Parse::RecDescent;
use Text::DelimMatch;

$::RD_ERRORS = 1;
$::RD_WARN = 1;
$::RD_HINT = 1;
$::RD_TRACE = 1;

my $grammar = q{
{
   sub parse_delimited {
        my $text       = shift;
        my $startdelim = shift;
        my $enddelim   = shift;

        my $mc = new Text::DelimMatch( $startdelim, $enddelim );
        my ( $p, $m, $r ) = $mc-&gt;match( $text );

        if ($p) {
            $text = $p;
        }
        else {
            $text = "";
        }
        $text .= $r if ($r);
        $m =~ s/^$startdelim//;
        $m =~ s/$enddelim$//;
        return $text, $m;
    }
}
file: line(s) eofile { use Data::Dumper 'Dumper'; print Dumper @item}

line:
    comment
    | &lt;error&gt;

eofile: /^\Z/

comment:
        &lt;skip: qr/[ \t]*/&gt; '/*'
        {
            ($text,$return) = $thisparser-&gt;parse_delimited($text, '/*', '*/');
             $return = ['comment',$return];
        }

};

my $parser = new Parse::RecDescent($grammar) or die "Bad grammar!\n";

while (&lt;DATA&gt;)
{
	chomp;
	print "$_...\n";
	defined($parser-&gt;file($_)) or print "Bad text!\n";
}

__DATA__
/*Hello
World
*/

&lt;/code&gt;

I also get the following errors in the trace which are disconcerting but I don't think it's causing the problem:
&lt;code&gt;
Argument "/*" isn't numeric in addition (+) at C:/Perl/site/lib/Parse/RecDescent.pm line 2783, &lt;DATA&gt; line 1.
Use of uninitialized value in substitution (s///) at (eval 15)[C:/Perl/site/lib/Parse/RecDescent.pm:2618] line 22, &lt;DATA&gt; line 1.
Use of uninitialized value in concatenation (.) or string at (eval 15)[C:/Perl/site/lib/Parse/RecDescent.pm:2618] line 23, &lt;DATA&gt; line 1.
Use of uninitialized value in substitution (s///) at (eval 15)[C:/Perl/site/lib/Parse/RecDescent.pm:2618] line 23, &lt;DATA&gt; line 1.
Use of uninitialized value in substitution (s///) at (eval 15)[C:/Perl/site/lib/Parse/RecDescent.pm:2618] line 23, &lt;DATA&gt; line 1.
&lt;/code&gt;

</field>
<field name="root_node">
180778</field>
<field name="parent_node">
180778</field>
</data>
</node>
