Use <{...}>. as the string returned is reinterpreted as a regex, if it consists 
of the single quoted string then it's a literal, but you must include the 
single quotes in the result returned.  E.g., 
<{ my $x = funct($a, $b, $c); "'$x'";}>

Mark Biggar
--
m...@biggar.org
mark.a.big...@comcast.net
mbig...@paypal.com

----- Original Message -----
From: Mark J. Reed 
To: perl6-language@perl.org
Sent: Mon, 29 Mar 2010 14:27:00 +0000 (UTC)
Subject: Regex interpolation

Is there not a way to run arbitrary code and interpolate the result as
a literal string (instead of a Regex)?

 I assume that {...} is intended to be where you hook in
semantics/actions mid-parse, but it seems a bit counter-intuitive that
the same syntax interpolates in double-quote context but not regexes.

Question Inspired by this Rakudo patch:
On Monday, March 29, 2010, Bruce Keeler  wrote:
> # New Ticket Created by  Bruce Keeler
> # Please include the string:  [perl #73862]
> # in the subject line of all future correspondence about this issue.
> # 
>
>
> The attached patch adds support for variable and block-result
> interpolation into regexes.
>
> It does so by means of a new PAST::Regex node pasttype 'interpolator'.
> The following syntaxes are supported by this patch:
>
>     / $var /  -- Interpolates as literal string, unless it's a Regex object
>     / @foo / -- Interpolated as ||-style alternations of literal strings
> or Regex objects
>     / <$var> / -- compiled into a Regex (unless it's already one), then
> interpolated
>     / <@foo> / -- A list of ||-style alternations of things to be
> compiled into Regexes (unless they already are)
>     / <{ ... }> / -- Result of capture is interpolated as a Regex,
> compiling if necessary
>     / / -- Unchanged
>     / { ... } / -- Capture is merely executed, but not interpolated.
> (Unchanged)
>

-- 
Mark J. Reed 

Reply via email to