--- Dave Whipp <[EMAIL PROTECTED]> wrote: > "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.
... > 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. > Actually, IMO this goes back to the conversation we had some time about about being able to run grammars/patterns against arbitrary objects. What you really want is to be able to "chain" grammars: > my $fh = open "<hello.c"; > $fh =~ /<Grammars::Languages::C>/; grammar Grammars::Languages::C { method init { SUPER::init; $.source = (new Grammars::Language::C::Preprocessor).open($source); } ... } grammar Grammars::Languages::C::Preprocessor { rule CompilationUnit { ( <Directive> | <UnprocessedStuff> )* } rule Directive { <Hash> ( Include | Line | Conditional | Define ) <Continuation>* } rule Hash { /^\s*#\s*/ } rule Include {...} rule Line {...} rule Conditional {...} rule Define {...} rule Continuation {...} rule UnprocessedStuff {...} } Except that it would probably be even better to do this arbitrarily. > my $fh = open "<hello.c"; > $fh =~ /<Grammars::Languages::C>/; $fh =~ /<Grammars::Languages::C(input_method = Grammars::Languages::C::Preprocessor)>/; (Of course, in reality the C grammar would automatically use the preprocessor as its input method without having to be told. But it should be able to do so as two separate grammars.) Likewise: my $fh = open "<perl.1.gz"; $fh =~ /<Grammars::Languages::Runoff::Nroff(input_method = Grammars::Languages::Runoff::tbl(input_method = Grammars::Language::Runoff::eqn(input_method = IO::Gunzip)))>/; =Austin