RE: Reset local parser variables for each new input file

[email protected] Mon, 13 Sep 2004 14:45:01 +0200
Newsgroups perl.recdescent
Message-ID <[email protected]>
Yes, I've tried that and it seems to work, but I'm=20
worried about the cases when the input files don't parse.
Will the mmpfile: { $i =3D 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]]
>=20
> 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:
>=20
> Can you just add an action to the beginning of your start rule, like =
so?
>=20
>   mmpfile: { $i =3D 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=20
#!/usr/bin/perl -w

use strict;
use Parse::RecDescent;
use constant GRAMMAR =3D> q(

{ my $i =3D 1; }

mmpfile: { $i =3D 1} letter(s) /^\Z/
letter: /([A-Z])/ { print "$i: <$1>\n"; $i++ }

);

my $parser =3D 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';