Yuri Shtil
2012-01-10 16:54:56 UTC
I use OO perl and created a class that uses recdecent.
I want to access method variables from the grammar actions. Is there an elegant way to pass a parameter to the Parse::RecDescent constructor and access it from the actions?
I used an awkward construct and I don't like it:
-----
Package Foo;
our $var;
...
my $grammar = '...
# Capture the object instance
my $object = Foo::$var;
startrule: a b c {$object->method}'
...
sub action {
# Capture $var
$var = SOmeClass->new();
# $var is used in grammar
my $parser = 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 may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
I want to access method variables from the grammar actions. Is there an elegant way to pass a parameter to the Parse::RecDescent constructor and access it from the actions?
I used an awkward construct and I don't like it:
-----
Package Foo;
our $var;
...
my $grammar = '...
# Capture the object instance
my $object = Foo::$var;
startrule: a b c {$object->method}'
...
sub action {
# Capture $var
$var = SOmeClass->new();
# $var is used in grammar
my $parser = 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 may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------