develooper Front page | perl.recdescent | Postings from November 2007

RFC - Parse::RecDescent::Slurp

Thread Previous | Thread Next
From:
terrence.x.brannon
Date:
November 2, 2007 12:24
Subject:
RFC - Parse::RecDescent::Slurp
Message ID:
OF44665847.7C442FBC-ON85257387.00675A71-85257387.006A6314@jpmchase.com
Large parts of my current grammar consist of alternation lists which are 
easier entered into a file as follows:

+the(?) /bahamas?/ #bahamas 
chile
cuba
/d(a|e)nmark/

The items preceded with a plus are non-terminals and entered literally
The iterms preceded with a slash are regexps and are entered literally
The other items get single quote marks put around them

And all items are thrown into an alternation, such as

country: the(?) /bahamas?/  # bahamas
       | 'chile'
       | 'cuba'
       | /d(a|e)nmark/

This saves me from typing double quotes.
And sorting the file makes it easy to check for duplicate entries. Which 
is very possible when entering as many records as I am.
And of course it is nice to have the main grammar much smaller.

I'm starting to like Class::Base for all my OOP work, so I would probably 
have an API like:

my $o = Parse::RecDescent::Slurp(base => 'path/to/data/files/');
for my $rule (qw(city country state)) {
   $grammar = sprintf "$grammar\n%s\n", $o->slurp($rule) ; # rule and data 
file name are the same unless 2nd arg gives rule explicit name
}

my $p = Parse::RecDescent->new($grammar);

or maybe I should provide the grammar to the constructor and have slurp 
automatically tack the rules on at the end...

at any rate, I dont like how Class::Base takes named parms for the 
constructor but positional parms for the methods... I think I will see 
what 
perlmonks like for their OO-work.

Just brainstorming for now anyway... 

--
Terrence Brannon - SID W049945
614-213-2475 (office)
614-213-3426 (fax)
818-359-0893 (cell)



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About