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