in reply to Using Parse::RecDescent in an Object

If I understand your question correctly, you could do this:

1. Create wanted object in the Start-up Action (see Parse::RecDescent documentation)
2. Fill object with parsed data
3. Return object in the startrule (if the grammar fails, undef is returned instead)

  • Comment on Re: Using Parse::RecDescent in an Object

Replies are listed 'Best First'.
Re^2: Using Parse::RecDescent in an Object
by ~~David~~ (Hermit) on Jun 10, 2010 at 18:32 UTC
    Thanks, I see the startup actions. It almost did what I wanted. What I have ended up doing ( and maybe this is bad ), is to make my file method look like this:
    sub file { my $self = shift; my $file = shift; our $object; $object = $self; if ( not -f $file ){ carp 'Invalid filename provided' }; my @grammer = <DATA>; my $grammer = join ' ', @grammer; my $parser = Parse::RecDescent->new( $grammer ); open my $file_h, '<', $file or croak q{Couldn't open file}; while ( my $line = <$file_h> ){ chomp $line; $self = $parser->startrule($line); } close $file_h; undef $object; return $file; }
    And all of my grammers use this syntax:
    Klarf::1_8::_store_line( $Klarf::1_8::object, $item{LINE}, 'col' )
    I will work on removing the hard coded package links if possible.