On Mon, Oct 27, 2008 at 10:24:56PM -0700, Chris Dolan wrote:
> As of parrot rev 32120, PGE only supports the old S05 closure syntax  
> that had double curlies like so
>     /foo {{ say "matched foo" }}/
> 
> The current S05 says this is legal:
>     /foo { say "matched foo" }/
> 
> This was discussed on perl6.users at:
>    http://www.nntp.perl.org/group/perl.perl6.users/2008/10/msg826.html
> 
> The attached patch allows one to use either single or double curlies  
> (or triple, etc, actually).  I added disambiguation for the "{*}"  
> token which is now a special case of "{...}".  Perhaps that latter  
> bit was over-engineering, but I don't grok the optable yet well  
> enough to understand how it disambiguates on its own.

In reality, what has to happen here is that encountering a opening
curly brace transfers parsing to the parser for the appropriate
language (e.g., Perl 6, PIR, etc.).  For example, consider a regex
like:

    /foo { if True { say '{yes}'; } } bar/

Upon encountering the first curly brace we cannot simply scan ahead
until the next closing curly brace we happen to find -- we actually 
have to transfer parsing to a different compiler (one that understands 
Perl 6), let that compiler parse as much as it can up to an unmatched 
closing curly brace, and return that result back to the regex parser to
continue parsing the rest of the regex.

This is why PGE currently requires at least two braces for open and
closing, (1) to make it clearer that parsing is being done via
a lookahead scan and not an actual parse, and (2) to avoid confusion
if the embedded code has any single curlies within it.

Beyond that, Parrot and PIR don't currently provide an easy way to
switch to/from a PIR parser, so for embedding PIR for the time being
we'll have to use some sort of lookahead scan to find the end of
the PIR string.

Pm

Reply via email to