logo       

Support for S05's new "result object"?: msg#00018

lang.perl.perl6.compiler

Subject: Support for S05's new "result object"?

Heya. Today I noted with delight that PGE supports interpolation of
closures:

$ parrot demo.pir
rule Foo {{ print "Hello" }}

Though the Perl 6 form is {...} instead of {{...}} -- is that intentional?

We have started self-hosting Perl6 compilation, beginning with a
self-hosting Rule engine; to construct the AST object, we use the
"return" form recently specified in S05.pod. Please see
http://perlcabal.org/~gaal/peek/slide37.html for an illustration of its use.

In a nutshell, the Match object can now function as a Code, and when you
call it (via $match() or $() or coercion), it yields the match "result
object". By default this is just the string (~$/), but one can set the
result object inside the rule with this syntax:

rule { Ferrari : { return Car.new(:color<red>) } }

This alleviates the need for an attribute-grammar pass to convert match
objects into ASTs, and allows selective parsing of subrules based on
querying earlier subrules' result objects.

Is it possible for PGE, with its embedded code closure, support
something like that? For example, make a lexical symbol RETURN
visible inside the interpolated block, which will set the result object
and return a match success at that position?

rule Foo {{
$P0 = new .Some::Tree
RETURN($P0)
}}

If available, this will greatly help Pugs to bootstrap its Haskell parts
off to Perl 6, as it allows us to translate the parser-combinator style
parsing into equivalent Perl 6 rules.

Pointers to where in the PGE source to hack this together would be
appreciated. :-)

Thanks,
Audrey

Attachment: signature.asc
Description: OpenPGP digital signature

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise