"Piers Cawley" <[EMAIL PROTECTED]> wrote > Parsers with Pre-processors > I didn't quite understand what Dave Whipp was driving at when he talked > about overloading the "<ws>" pattern as a way of doing preprocessing of > Perl 6 patterns. I didn't understand Luke Palmer's answer either. Help.
Let me see if I can clarify a bit. The new Grammar engine in P6 is designed to parse whole files. In fact, I hope to be able to say: my $fh = open "<hello.c"; $fh =~ /<Grammars::Languages::C>/; (Or something similar). This style of parsing differs from the traditional model in that there is no preprocessor (and no lexer, either). In C, it is possible to add a "#include "foo.h" statement almost anywhere. It would get very tedious to allow it in every prduction rule of the grammar (and also unmaintainable, unreadable, ..., unusable). So it has to be possible to say "when matching this C-file against this grammar: allow '#include ...' almost anywhere." It just so happens that "almost anywhere" has a precise definition: "anywhere where whitespace is legal". It also just so happens that Perl6 patterns have a :w modifier to enable a grammar writer to avoid placing a <ws> assertion in every production rule. So I have 3 axioms: * I want to avoid adding preprocesor-rule productions "almost everywhere" * "almost everywhere" means "anywhere whitespace is legal" * :w modifier automatically allows whitespace anywhere whitespace is legal (almost). I believe that an obvious inference is that :w processing should include the preprocessor parsing. Then the issue becomes one of mechanism: how do we tell :w what our (complex) definition of whitespace is; and how to we implement the preprocessor commands to modify the input-stream to the regex engine. Even though I'm not sure that my original answers are correct (perhaps some form of C<temp> would be a better approach), I'll refer you back to my original post (and Luke's reply) for those details. I also need to think about how C-macros would be implemented. > http://xrl.us/mt2 Dave.