Yes, I've tried that and it seems to work, but I'm worried about the cases when the input files don't parse. Will the mmpfile: { $i = 1 } still always trigger?
Also, what is it? It's not an action for the mmprule, isn't it? > -----Original Message----- > From: ext Sean O'Rourke [mailto:[EMAIL PROTECTED] > > At Mon, 13 Sep 2004 10:04:37 +0200, <[EMAIL PROTECTED]> wrote: > > Something like the "Start-up actions" from the "perldoc P::RecDescent", > > but they should be reset on every new parser call and not just on the > > grammar compilation, like here: > > Can you just add an action to the beginning of your start rule, like so? > > mmpfile: { $i = 1 } letter(s) /^\Z/ bolinux72:afarber {514} perl test_pd.pl 1: <A> 2: <B> 3: <C> Bad text 2 at test_pd.pl line 16. 1: <X> 2: <Y> 3: <Z> bolinux72:afarber {515} cat test_pd.pl #!/usr/bin/perl -w use strict; use Parse::RecDescent; use constant GRAMMAR => q( { my $i = 1; } mmpfile: { $i = 1} letter(s) /^\Z/ letter: /([A-Z])/ { print "$i: <$1>\n"; $i++ } ); my $parser = Parse::RecDescent->new(GRAMMAR) or die 'Bad grammar'; defined $parser->mmpfile('ABC') or warn 'Bad text 1'; defined $parser->mmpfile('klm') or warn 'Bad text 2'; defined $parser->mmpfile('XYZ') or warn 'Bad text 3';