Author: bernhard
Date: Wed Mar 28 11:41:51 2007
New Revision: 17815

Modified:
   trunk/languages/plumhead/src/common/builtins.pir
   trunk/languages/plumhead/src/partridge/Plumhead.pg
   trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
   trunk/languages/plumhead/t/hello.t

Log:
[Plumhead partridge]
Add support for string concatenation.


Modified: trunk/languages/plumhead/src/common/builtins.pir
==============================================================================
--- trunk/languages/plumhead/src/common/builtins.pir    (original)
+++ trunk/languages/plumhead/src/common/builtins.pir    Wed Mar 28 11:41:51 2007
@@ -228,6 +228,15 @@
     .return ($I0)
 .end
 
+.sub 'infix:~'
+    .param string a
+    .param string b
+
+    $S0 = concat a, b
+
+    .return ($S0)
+.end
+
 .sub 'error_reporting'
   .return()
 .end

Modified: trunk/languages/plumhead/src/partridge/Plumhead.pg
==============================================================================
--- trunk/languages/plumhead/src/partridge/Plumhead.pg  (original)
+++ trunk/languages/plumhead/src/partridge/Plumhead.pg  Wed Mar 28 11:41:51 2007
@@ -28,6 +28,7 @@
 
 token UNARY_MINUS             { \- }
 token UNARY_PLUS              { \+ }
+token CONCAT_OP               { \. }
 token ADD_OP                  { \+ | \- }
 token MUL_OP                  { \* | / | % }
 token BITWISE_OP              { <'|'>  | <'&'> | <'^'> }
@@ -60,8 +61,7 @@
 rule  scalar_assign           { <var> <ASSIGN_OP> <expression> ( ; | <?before: 
\? > | $ ) }
 rule  array_assign            { <array_elem> <ASSIGN_OP> <expression> ( ; | 
<?before: \? > | $ ) }
 
-token expression              {   <DOUBLEQUOTE_STRING>
-                                | <SINGLEQUOTE_STRING>
+token expression              {   <concat_expression>
                                 | <bitwise_expression>
                                 | <array_elem>
                                 | <var>
@@ -71,6 +71,10 @@
 rule  array_key               { <expression>  }
 rule  var                     { <VAR_NAME> }
 
+rule concat_expression        { <string> <concat_tail>* }
+rule string                   { <DOUBLEQUOTE_STRING> | <SINGLEQUOTE_STRING> }
+rule concat_tail              { <CONCAT_OP> <string> }
+
 rule bitwise_expression       { <adding_expression> <bitwise_tail>? }
 
 rule bitwise_tail             { <BITWISE_OP> <adding_expression> }

Modified: trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
==============================================================================
--- trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      (original)
+++ trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      Wed Mar 28 
11:41:51 2007
@@ -236,6 +236,43 @@
         goto handled_expression
     no_array_elem_1:
 
+    $P0 = node['concat_expression']
+    if null $P0 goto no_concat_expression
+        .local pmc past_string, concat_tail, concat_tail_iter
+        past = tree.'get'('past', $P0, 'Plumhead::Grammar::expression')
+        concat_tail = $P0['concat_tail']
+        if null concat_tail goto no_concat_tail
+            .local pmc past_prev, cnode 
+            concat_tail_iter = new .Iterator, concat_tail
+            iter_loop_concat:
+                unless concat_tail_iter goto iter_end_concat
+                .local pmc cnode
+                cnode = shift concat_tail_iter
+                past_string = tree.'get'('past', cnode, 
'Plumhead::Grammar::expression')
+                past_prev = past
+
+                .local string op
+                op = cnode['CONCAT_OP']
+                if op != '.' goto not_concat
+                    op = '~'
+                not_concat:
+                op = 'infix:' . op 
+                past = new 'PAST::Op'
+                past.init( past_prev, past_string, 'name' => op )
+                goto iter_loop_concat
+            iter_end_concat:
+            goto handled_expression
+        no_concat_tail:
+            past = tree.'get'('past', $P0, 'Plumhead::Grammar::expression')
+            goto handled_expression
+    no_concat_expression:
+
+    $P0 = node['string']
+    if null $P0 goto no_string
+        past = tree.'get'('past', $P0, 'Plumhead::Grammar::expression')
+        goto handled_expression
+    no_string:
+
     $P0 = node['DOUBLEQUOTE_STRING']
     if null $P0 goto no_DOUBLEQUOTE_STRING
         past = tree.'get'('past', $P0, 'Plumhead::Grammar::DOUBLEQUOTE_STRING')
@@ -296,8 +333,8 @@
         if null adding_tail goto handled_expression
             .local pmc past_prev, cnode 
             adding_tail_iter = new .Iterator, adding_tail
-            iter_loop:
-                unless adding_tail_iter goto iter_end
+            iter_loop_adding:
+                unless adding_tail_iter goto iter_end_adding
                 .local pmc cnode
                 cnode = shift adding_tail_iter
                 past_mult = tree.'get'('past', cnode, 
'Plumhead::Grammar::expression')
@@ -311,8 +348,8 @@
                 add_op = 'infix:' . add_op 
                 past = new 'PAST::Op'
                 past.init( past_prev, past_mult, 'name' => add_op, 'pirop' => 
pirop )
-                goto iter_loop
-            iter_end:
+                goto iter_loop_adding
+            iter_end_adding:
             goto handled_expression
     no_adding_expression:
 

Modified: trunk/languages/plumhead/t/hello.t
==============================================================================
--- trunk/languages/plumhead/t/hello.t  (original)
+++ trunk/languages/plumhead/t/hello.t  Wed Mar 28 11:41:51 2007
@@ -18,7 +18,7 @@
 use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../../lib";
 
 # core Perl modules
-use Test::More     tests => 14;
+use Test::More     tests => 16;
 
 # Parrot modules
 use Parrot::Test;
@@ -172,3 +172,21 @@
 Hello, World!
 END_EXPECTED
 
+
+language_output_is( 'Plumhead', <<'END_CODE', <<'END_EXPECTED', 'concatenation 
of two strings' );
+<?php
+echo 'Hello, ' . "World!\n"
+?>
+END_CODE
+Hello, World!
+END_EXPECTED
+
+
+language_output_is( 'Plumhead', <<'END_CODE', <<'END_EXPECTED', 'concatenation 
of four strings' );
+<?php
+echo 'Hell' . 'o, ' . 'World!' . "\n"
+?>
+END_CODE
+Hello, World!
+END_EXPECTED
+

Reply via email to