How to access a variable from the grammar code
[email protected] (Yuri Shtil) Tue, 10 Jan 2012 08:54:56 -0800
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
--_000_5F72830DCCB3CC4FBF80CC854C3999F18E9ED87854HQMAIL02nvidi_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
I use OO perl and created a class that uses recdecent.
I want to access method variables from the grammar actions. Is there an e=
legant way to pass a parameter to the Parse::RecDescent constructor and a=
ccess it from the actions?
I used an awkward construct and I don't like it:
-----
Package Foo;
our $var;
...
my $grammar =3D '...
# Capture the object instance
my $object =3D Foo::$var;
startrule: a b c {$object->method}'
...
sub action {
# Capture $var
=20 $var =3D SOmeClass->new();
# $var is used in grammar
my $parser =3D Parse::RecDescent ($grammar);
$parser->startrule(SomeText);
}
Also I think this would not work with Precompile.
-------------------------------------------------------------------------=
----------
This email message is for the sole use of the intended recipient(s) and m=
ay contain
confidential information. Any unauthorized review, use, disclosure or di=
stribution
is prohibited. If you are not the intended recipient, please contact the=
=20sender by
reply email and destroy all copies of the original message.
-------------------------------------------------------------------------=
----------
--_000_5F72830DCCB3CC4FBF80CC854C3999F18E9ED87854HQMAIL02nvidi_--