Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add closure interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Nov 8, 2009
1 parent 57d2a44 commit 5559916
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -553,6 +553,11 @@ method quote:sym<Q:PIR>($/) {
}

method quote_escape:sym<$>($/) { make $<variable>.ast; }
method quote_escape:sym<{ }>($/) {
make PAST::Op.new(
:pirop('set S*'), block_immediate($<block>.ast), :node($/)
);
}

## Operators

Expand Down
3 changes: 2 additions & 1 deletion src/NQP/Grammar.pm
Expand Up @@ -333,7 +333,8 @@ token quote:sym<qq> { 'qq' <![(]> <.ws> <quote_EXPR: ':qq'> }
token quote:sym<Q> { 'Q' <![(]> <.ws> <quote_EXPR> }
token quote:sym<Q:PIR> { 'Q:PIR' <.ws> <quote_EXPR> }

token quote_escape:sym<$> { <?[$]> <?quotemod_check('s')> <variable> }
token quote_escape:sym<$> { <?[$]> <?quotemod_check('s')> <variable> }
token quote_escape:sym<{ }> { <?[{]> <?quotemod_check('c')> <block> }

token circumfix:sym<( )> { '(' <.ws> <EXPR> ')' }
token circumfix:sym<ang> { <?[<]> <quote_EXPR: ':q', ':w'> }
Expand Down
10 changes: 9 additions & 1 deletion t/nqp/38-quotes.t
Expand Up @@ -2,10 +2,18 @@

# interpolating quotes

plan(2);
plan(4);

my $abc := 'abc';

ok( "xxx$abc" eq 'xxxabc', "basic scalar interpolation" );

ok( qq{xxx $abc zzz} eq 'xxx abc zzz', 'basic qq{} interpolation' );

my $num := 5;

ok( "xxx {3+$num} zzz" eq 'xxx 8 zzz', "basic closure interpolation" );

ok( qq{xxx {3+$num} zzz} eq 'xxx 8 zzz', "basic qq{} closure interpolation" );


0 comments on commit 5559916

Please sign in to comment.