[svn:parrot] r38768 - in trunk/compilers/nqp: src src/Grammar t
pmichaud at svn.parrot.org
pmichaud at svn.parrot.org
Thu May 14 06:06:14 UTC 2009
Author: pmichaud
Date: Thu May 14 06:06:14 2009
New Revision: 38768
URL: https://trac.parrot.org/parrot/changeset/38768
Log:
[nqp]: Port Q:PIR notation from Rakudo.
Modified:
trunk/compilers/nqp/src/Grammar.pg
trunk/compilers/nqp/src/Grammar/Actions.pir
trunk/compilers/nqp/t/18-inline.t
Modified: trunk/compilers/nqp/src/Grammar.pg
==============================================================================
--- trunk/compilers/nqp/src/Grammar.pg Thu May 14 04:53:06 2009 (r38767)
+++ trunk/compilers/nqp/src/Grammar.pg Thu May 14 06:06:14 2009 (r38768)
@@ -338,11 +338,12 @@
}
token quote {
- [ \' <string_literal: '\''> \'
- | '"' <string_literal: '"'> '"'
- | 'q' <.ws> '<' <string_literal: '>'> '>'
+ [ \' <string_literal: '\''> \' {*} #= string
+ | '"' <string_literal: '"'> '"' {*} #= string
+ | 'q' <.ws> '<' <string_literal: '>'> '>' {*} #= string
+ | 'Q' <.ws> ':PIR' <.ws>
+ [:ratchet(0) '{{' (.*?) '}}' | '{' (.*?) '}' ] {*} #= PIR
]
- {*}
}
Modified: trunk/compilers/nqp/src/Grammar/Actions.pir
==============================================================================
--- trunk/compilers/nqp/src/Grammar/Actions.pir Thu May 14 04:53:06 2009 (r38767)
+++ trunk/compilers/nqp/src/Grammar/Actions.pir Thu May 14 06:06:14 2009 (r38768)
@@ -905,16 +905,29 @@
## method quote($/, $key) {
-## make PAST::Val.new( :node($/), :value(~($<string_literal>)) );
+## if $key eq 'PIR' {
+## make PAST::Op.new( :node($/), :inline(~($[0])) );
+## }
+## else {
+## make PAST::Val.new( :node($/), :value(~($<string_literal>)) );
+## }
## }
.sub 'quote' :method
.param pmc match
.param pmc key :optional
.local string value
+ unless key == 'PIR' goto quote_string
+ quote_pir:
+ $S0 = match[0]
+ $P0 = get_hll_global ['PAST'], 'Op'
+ $P1 = $P0.'new'('node'=>match, 'inline'=>$S0)
+ goto end
+ quote_string:
$P0 = match['string_literal']
value = $P0.'ast'()
$P0 = get_hll_global ['PAST'], 'Val'
$P1 = $P0.'new'('node'=>match, 'value'=>value)
+ end:
match.'!make'($P1)
.end
Modified: trunk/compilers/nqp/t/18-inline.t
==============================================================================
--- trunk/compilers/nqp/t/18-inline.t Thu May 14 04:53:06 2009 (r38767)
+++ trunk/compilers/nqp/t/18-inline.t Thu May 14 06:06:14 2009 (r38768)
@@ -2,7 +2,7 @@
# inline
-plan(5);
+plan(7);
PIR q< say 'ok 1' >;
PIR q:to:'OK2';
@@ -17,3 +17,8 @@
PIR q:to:"OK5";
say 'ok 5'
OK5
+
+Q:PIR { say 'ok 6' };
+my $x := Q:PIR { %r = box 'ok 7' };
+say($x);
+
More information about the parrot-commits
mailing list