Hi,

why doesn't the question mark in the optarg(?)
below work as I expect? In the trace I see that
optarg consumes the ">" character and then the
option rule fails, since the final ">" is missing.

Isn't P:RD supposed to backtrack and say 
"ok, the optarg(?) didn't match anything here"?

Of course the script below works when I change
the optarg from /\S+/ to /\w+/, but I'm curious,
why doesn't optarg(?) mean "ZERO or one" here?

Thank you
Alex

#!/usr/bin/perl -w

use strict;
use vars qw($parser $text %option);
use Data::Dumper;
use Parse::RecDescent;
$RD_WARN  = 1;
$RD_HINT  = 1;
$RD_TRACE = 120;
$parser = Parse::RecDescent->new(q(

genfile: chunk(s) /^\Z/
chunk: option | <error>
option: /<option/i /\w+/ optarg(?) ">" {
        push @{$::option{lc $item[2]}}, $item[-2];
} 
optarg: /\S+/

)) or die 'Bad grammar';
$text .= $_ while (<DATA>);
defined $parser->genfile($text) or die 'Bad text';
print STDERR Data::Dumper->Dump([\%option], [qw(option)]);
__DATA__
<option one>
<option two>


Reply via email to