Message from discussion
How to access a variable from the grammar code
Received: by 10.68.117.197 with SMTP id kg5mr11456481pbb.5.1326214805170;
Tue, 10 Jan 2012 09:00:05 -0800 (PST)
Newsgroups: perl.recdescent
Path: lh20ni164266pbb.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!nntp.develooper.com!nntp.perl.org
Return-Path: <ysh...@nvidia.com>
Mailing-List: contact recdescent-h...@perl.org; run by ezmlm
Delivered-To: mailing list recdesc...@perl.org
Received: (qmail 28526 invoked from network); 10 Jan 2012 16:55:06 -0000
Received: from x1.develooper.com (207.171.7.70)
by x6.develooper.com with SMTP; 10 Jan 2012 16:55:06 -0000
Received: (qmail 15032 invoked by uid 225); 10 Jan 2012 16:55:06 -0000
Delivered-To: recdesc...@perl.org
Received: (qmail 15018 invoked by alias); 10 Jan 2012 16:55:05 -0000
X-Spam-Status: No, hits=-2.3 required=8.0
tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: la.mx.develooper.com
Received: from hqemgate03.nvidia.com (HELO hqemgate03.nvidia.com) (216.228.121.140)
by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Tue, 10 Jan 2012 08:55:02 -0800
Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com
id <B4f0c70a00000>; Tue, 10 Jan 2012 09:08:48 -0800
Received: from hqemhub02.nvidia.com ([172.17.108.22])
by hqnvupgp08.nvidia.com (PGP Universal service);
Tue, 10 Jan 2012 08:54:59 -0800
X-PGP-Universal: processed;
by hqnvupgp08.nvidia.com on Tue, 10 Jan 2012 08:54:59 -0800
Received: from HQMAIL02.nvidia.com ([172.20.150.110]) by hqemhub02.nvidia.com
([172.20.150.31]) with mapi; Tue, 10 Jan 2012 08:54:58 -0800
To: "recdesc...@perl.org" <recdesc...@perl.org>
Date: Tue, 10 Jan 2012 08:54:56 -0800
Subject: How to access a variable from the grammar code
Thread-Topic: How to access a variable from the grammar code
Thread-Index: AczPtyw/cPY3R2/dTNa8zZtPtPUl8g==
Message-ID: <5F72830DCCB3CC4FBF80CC854C3999F18E9ED87854@HQMAIL02.nvidia.com>
Accept-Language: en-US
acceptlanguage: en-US
MIME-Version: 1.0
X-Virus-Checked: Checked
Approved: n...@nntp.perl.org
From: ysh...@nvidia.com (Yuri Shtil)
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.
-------------------------------------------------------------------------=
----------