On Mon, Jul 04, 2005 at 05:19:06PM -0400, Matt Diephouse wrote:
> What is the plan for integrating code blocks into PGE? Will Coleda
> mentioned on IRC that this issue came up at YAPC, but didn't seem to
> indicate that there was any plan. As we transition to using PGE for
> Tcl parsing, it'd be nice to have code blocks.

Oh, there is definitely a plan (several, in fact), however, getting
code blocks to work properly requires some coordination between
PGE and the underlying compiler language.  In short, when PGE's
parser encounters a code block, it needs to hand off control to
the target language's compiler to parse to the end of the
code block and receive back from that compiler the length of
the block parsed.

Or, we try to do something along the lines of Text::Balanced and
find the closing brace by doing simple delimiter counting, but
Perl 6 brings in several new delimiters that have to be taken into
account in the balancing act.

> Specifically, it'd be nice to be able to specify a compiler to use
> along with a code block. In the immediate future, it'd be nice if we
> could use PIR for these. That would allow us to throw exceptions to
> catch parse errors.

For PIR there is already a possibility -- simply define a subrule
that executes the PIR code desired.  For example, one can do:

    .sub throw
        .param pmc mob                 # match object
        # execute whatever code you want here
        # ...

        # to return "success" to the matching engine
        $P0 = getattribute mob, "PGE::Match\x0$:from"
        $P1 = getattribute mob, "PGE::Match\x0$:pos"
        assign $P1, $P0
        .return (mob)         
    .end

and then the <throw> subrule will execute the PIR subroutine.
I'm currently working on the parameterized subrule syntax from 
A05/S05, so that one would be able to do:

    <throw:Don't do that!>

and the string "Don't do that!" would be passed as a parameter
to the "throw" subrule (where it could be printed, parsed,
etc).

Pm

Reply via email to