> We're not quite in the world of ACME::DWIM, so you can't just replace
> the important stuff with ... .  :-)

Maybe, but the C preprocessor isn't important, here, for itself. Otherwise I
could cheat:

  grammar Grammar::Language::C::Preprocessor {
    rule CompilationUnit {
        FIRST { static $cheat = open "|/bin/cc -E|"; }
        <.*>  { $cheat.print $1; $cheat.inputRecordSep(""); return <$cheat>; }
    }
  }

> You're not outputting a parse tree, you're just outputting more text
> to be parsed with another, text-based, grammar.  It seems to me like
> it's a big s//ubstitution, of sorts.

It would, unless you were trying to do something other than preprocess C
files with your C preprocessor grammar. (e.g., build a C interpreter).

I think the right thing here is for "filter" type grammars to make sure that
the match objects they return can instantiate as a collection of the "right
things".

So if I want to treat the parse tree as a parse tree, great. But if I want
to treat it as an input stream, or an array of char, or whatever it takes to
compose grammars, that should be okay, too.

This goes back to your suggestion about mixing in interfaces. I still think
that's worth while, and here's another good example of why: if
Grammar::Language::C::Preprocessor implements all the methods necessary to
qualify (even nominally) as a stream or string, then so be it: it's a stream
or string. Now we can compose grammars infinitely, as long as we understand
(at the developer level) what the hell we're doing.

There should be no question of the utility of this. The C preprocessor has
shown up in an awful lot of strange places. Imake and XRDB spring
immediately to mind, of course.

Someone else pointed out the probable utility of the pipeline operators for
this kind of thing. They're right, too. That idiom reads too well to pass
up.

  $fh =~ <Grammar::Language::C <== Grammar::Language::C::Preprocessor>;

In fact, it might legitimately work the other way around, too:

  $fh =~ <Grammar::Language::C::Preprocessor ==> Grammar::Language::C>;

After all, "invoking" the C grammar on another grammar is a pretty obvious
idiom for composition.

This is just a question of idiomry, I think. (Or is it idiocy?)

=Austin

Reply via email to