Modular grammars?
[email protected] (Marcel Grunauer)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <20011028100320.IQBU14739.viefep12-int.chello.at@localhost> |
Having used the fantastically useful and flexible Parse::RecDescent
for a while, I have discovered a few techniques that may or may
not be useful to other people, and I'm going to post some of them
separately.
Maybe there are existing features that make some of these things
a lot easier and I've just missed them - in any case, let's discuss
it on this list.
One thing I'd like are modular grammars. That is, grammars encapsulated
in modules.
I've had to parse files of the general structure
bulletin header
report of type A line
report of type A line
and some other file looking like
bulletin header
report of type B line
report of type B line
Now these files share the same header. I wanted to just say the
equivalent of a use() statement, maybe a directive like
<require: Bulletin::Header>
that would bring in the required grammar. Although that kind of
directive would have to be parsed at parser-construction time.
And I have constructed such a mechanism that scans a grammar for
such directives, brings in the module, asks for its grammar (using
a grammar() function) and inserts it. This kinda works, and I'd be
happy to make that mechanism available, but maybe there is some
other way this problem could be solved (sans copy-and-paste of
grammars, which is precisely what I want to avoid).
Maybe $thisparser could be used to achieve such a thing, but I'm
not sure.
Thoughts? Ideas?
Marcel
--
Aspect-Oriented Perl http://codewerk.unixbeard.net/aspects/
cpan> install Aspect