Caleb C. wrote:
Ouch. But this is a good candidate for using Polyglot. Just name
your files .rbe, and when you require ‘endless’, it registers that
extension with Polyglot to be used with the endless loader. Then
you can just “require ‘fred’”, and it will endless-load “fred.rbe”.
This is very interesting, I could use this in RubyMacros as well. But
then that brings up another issue; what if I want to use both at once?
I think you’d need to create a custom loader that knows how to load the
file having combined syntax.
When Nathan Sobo created Treetop, one of his hopes was that Ruby
could eventually incorporate PEG parsing technology and add his “rule”
keyword. Because PEG parsers are composable, this would allow you to
define new parse rules within a Ruby program, which would integrate
fully into the existing Ruby grammar, or be used to introduce new
sub-languages that mesh in nicely… My take on that was then to
extend Kernel.require so that each file extension used a different
top-level parse rule from within the combined grammar, and you have
a full meta-language framework… That’s kinda what Polyglot is about.
It’s kinda what you’re talking about below, but done “properly”.
Aside from the trouble of actually getting the two to work together,
how does a user specify that some particular combination of
preprocessors is to be used? Extending your example, I could use .rbm
for files with macros in them, but what about files without ends and
with macros? .rbem? While Polyglot’s extension registration system is
nice, I’m wanting something more sophisticated as well.
Rails went with chained processors, like file.html.erb, etc. Polyglot’s
loader isn’t currently defined to read the input file and yield content
for a subsequent loader, but chaining like that is a possible extension.
I’m not entirely sure, but it seems like he’s saying that if you
should be able to require “languageConverter_f77.rb”, and then write
the rest of the file in fortran. A bit far-fetched, but I like the
idea of being able to declare the format up at the top of the file,
perhaps with a magic comment.
Why not think about providing a mechanism which provides this possibility?
Hmm, what about it, Clifford? Seems like an appropriate thing to add
It’s certainly possible. How would one loader pass output to the next?
I wouldn’t want to create the intermediate content as files.
PS: the examples on this page got damaged somehow:
Thanks, I’ll look at it.