Author: bernhard
Date: Fri Mar 30 13:24:42 2007
New Revision: 17864

Modified:
   trunk/languages/plumhead/src/partridge/Plumhead.pg
   trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
   trunk/languages/plumhead/t/superglobals.t

Log:
[Plumhead partridge]
Add support for
     echo php_sapi_name();


Modified: trunk/languages/plumhead/src/partridge/Plumhead.pg
==============================================================================
--- trunk/languages/plumhead/src/partridge/Plumhead.pg  (original)
+++ trunk/languages/plumhead/src/partridge/Plumhead.pg  Fri Mar 30 13:24:42 2007
@@ -17,6 +17,7 @@
 token SINGLEQUOTE_STRING      { ' <-[']>* ' }
 token ECHO                    { <'echo'> }
 token VAR_DUMP                { <'var_dump'> }
+token PHP_SAPI_NAME           { <'php_sapi_name'> }
 token PAREN_OPEN              { \( }
 token PAREN_CLOSE             { \) }
 
@@ -44,13 +45,12 @@
 
 rule relational_expression    { <expression> <rel_op_clause>? }
 
-rule statement                {
-    <ECHO> <expression>  ( ; | <?before: \? > | $ )
-  | <VAR_DUMP> <?PAREN_OPEN>  <expression> <?PAREN_CLOSE> ( ; | <?before: \? > 
| $ )
-  | <IF> <?PAREN_OPEN> <relational_expression> <?PAREN_CLOSE> \{ <statement>* 
\} <else_clause>? 
-  | <inline_sea> 
-  | <scalar_assign>
-  | <array_assign>
+rule statement                { <ECHO> ( <expression> | <PHP_SAPI_NAME> 
<?PAREN_OPEN> <?PAREN_CLOSE> )  ( ; | <?before: \? > | $ )
+                              | <VAR_DUMP> <?PAREN_OPEN>  <expression> 
<?PAREN_CLOSE> ( ; | <?before: \? > | $ )
+                              | <IF> <?PAREN_OPEN> <relational_expression> 
<?PAREN_CLOSE> \{ <statement>* \} <else_clause>? 
+                              | <inline_sea> 
+                              | <scalar_assign>
+                              | <array_assign>
                               }
 
 rule else_clause              { <?ELSE> \{ <statement>* \} }
@@ -82,7 +82,7 @@
 
 rule adding_tail              { <ADD_OP> <multiplying_expression> }
 
-# TODO: this gets precedence  wrong
+# TODO: this gets precedence wrong, see adding_expression
 rule multiplying_expression   { <unary_expression> <multiplicand>? }
 
 rule multiplicand             { <MUL_OP> <multiplying_expression> }
@@ -95,4 +95,3 @@
                               | <array_elem>
                               | <var>
                               }
-

Modified: trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
==============================================================================
--- trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      (original)
+++ trunk/languages/plumhead/src/partridge/PlumheadPAST.tg      Fri Mar 30 
13:24:42 2007
@@ -91,14 +91,26 @@
 
                  $P1 = cnode['ECHO']
                  if null $P1 goto no_echo
-                     $P2 = cnode['expression']
-                     if null $P2 goto iter_loop
+                     $P3  = cnode[0]
+                     $P2 = $P3['expression']
+                     if null $P2 goto no_expression_in_echo
                          past_expression = tree.'get'('past', $P2, 
'Plumhead::Grammar::expression')
                          if null past_expression goto iter_loop
                          past_echo = new 'PAST::Op'
                          past_echo.'init'( past_expression, 'node'=> node, 
'name' => 'print' )  
                          past.'push'(past_echo)
                          goto iter_loop
+                     no_expression_in_echo:
+                     $P2 = $P3['PHP_SAPI_NAME']
+                     if null $P2 goto no_php_sapi_name_in_echo
+                         past_expression = tree.'get'('past', $P3, 
'Plumhead::Grammar::expression')
+                         if null past_expression goto iter_loop
+                         past_echo = new 'PAST::Op'
+                         past_echo.'init'( past_expression, 'node'=> node, 
'name' => 'print' )  
+                         past.'push'(past_echo)
+                         goto iter_loop
+                     no_php_sapi_name_in_echo:
+                     goto iter_loop
                  no_echo:
 
                  $P1 = cnode['VAR_DUMP']
@@ -421,6 +433,13 @@
         goto handled_expression
     no_var_name:
 
+    $P0 = node['PHP_SAPI_NAME']
+    if null $P0 goto no_php_sapi_name
+        past = new 'PAST::Op'
+        past.'init'( 'node'=> node, 'name' => 'php_sapi_name' )  
+        goto handled_expression
+    no_php_sapi_name:
+
     handled_expression:
 
     .return (past)

Modified: trunk/languages/plumhead/t/superglobals.t
==============================================================================
--- trunk/languages/plumhead/t/superglobals.t   (original)
+++ trunk/languages/plumhead/t/superglobals.t   Fri Mar 30 13:24:42 2007
@@ -21,10 +21,7 @@
 use Parrot::Test;
 use Test::More     tests => 3;
 
-TODO: {
-    local $TODO = 'no support for functions returning a value';
-
-    language_output_is( 'Plumhead', <<'END_CODE', <<'END_EXPECTED', 
'php_sapi_name' );
+language_output_is( 'Plumhead', <<'END_CODE', <<'END_EXPECTED', 
'php_sapi_name' );
 <?php
 echo php_sapi_name();
 echo "\n";
@@ -33,8 +30,6 @@
 cgi-fcgi
 END_EXPECTED
 
-}
-
 $ENV{REQUEST_TYPE} = 'GET';
 $ENV{QUERY_STRING} = 'as=df';
 

Reply via email to