# New Ticket Created by "Daniel Keane"
# Please include the string: [perl #61620]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61620 >
A small patch to add do-while functionality to pipp.
Files changed:
* t/php/control_flow.t - add 2 tests for do-while statement
* src/pct/actions.pm - add action method 'do_while_statement'
* src/pct/grammer.pg - add rule 'do_while_statement'
* CREDITS - add email address and above patch
Thanks
Index: t/php/control_flow.t
===================================================================
--- t/php/control_flow.t (revision 34246)
+++ t/php/control_flow.t (working copy)
@@ -24,7 +24,7 @@
use Parrot::Config ();
use Parrot::Test;
-use Test::More tests => 16;
+use Test::More tests => 18;
language_output_is( 'Pipp', <<'CODE', <<'OUT', 'if, one statement in block' );
<?php
@@ -219,6 +219,43 @@
round 10
OUT
+language_output_is('Pipp', <<'CODE', <<'OUT', 'do-while loop');
+<?php
+
+$count = 0;
+do { echo "round $count\n"; $count++; } while ($count <= 10);
+CODE
+round 0
+round 1
+round 2
+round 3
+round 4
+round 5
+round 6
+round 7
+round 8
+round 9
+round 10
+OUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'do-while with negated expression');
+<?php
+
+$count = 0;
+do { $count++; echo "round $count\n"; } while (!($count >= 10));
+CODE
+round 1
+round 2
+round 3
+round 4
+round 5
+round 6
+round 7
+round 8
+round 9
+round 10
+OUT
+
language_output_is( 'Pipp', <<'CODE', <<'OUT', 'classic for-loop' );
<?php
Index: src/pct/actions.pm
===================================================================
--- src/pct/actions.pm (revision 34246)
+++ src/pct/actions.pm (working copy)
@@ -234,13 +234,23 @@
method conditional_expression($/) {
my $past := PAST::Op.new(
- $( $<expression> ),
- $( $<block> ),
+ $($<expression>),
+ $($<block>),
:node($/)
);
make $past;
}
+method do_while_statement($/) {
+ my $past := PAST::Op.new(
+ $($<expression>),
+ $($<block>),
+ :pasttype('repeat_while'),
+ :node($/)
+ );
+ make $past;
+}
+
method if_statement($/) {
my $past := $($<conditional_expression>);
$past.pasttype('if');
@@ -277,13 +287,13 @@
}
method else_clause($/) {
- make $($<block>);
+ make $($<block>);
}
method elseif_clause($/) {
- my $past := $($<conditional_expression>);
- $past.pasttype('if');
- make $past;
+ my $past := $($<conditional_expression>);
+ $past.pasttype('if');
+ make $past;
}
method var_assign($/) {
make PAST::Op.new(
Index: src/pct/grammar.pg
===================================================================
--- src/pct/grammar.pg (revision 34246)
+++ src/pct/grammar.pg (working copy)
@@ -126,6 +126,7 @@
| <expression_statement> {*} #= expression_statement
| <if_statement> {*} #= if_statement
| <while_statement> {*} #= while_statement
+ | <do_while_statement> {*} #= do_while_statement
| <for_statement> {*} #= for_statement
| <inline_sea_short_tag> {*} #= inline_sea_short_tag
| <inline_sea_script_tag> {*} #= inline_sea_script_tag
@@ -198,6 +199,11 @@
{*}
}
+rule do_while_statement {
+ 'do' <block> 'while' '(' <expression> ')' <.statement_delimiter>
+ {*}
+}
+
rule for_statement {
'for' '(' <var_assign> <expression> ';' <expression> ')' <block>
{*}
Index: CREDITS
===================================================================
--- CREDITS (revision 34246)
+++ CREDITS (working copy)
@@ -26,4 +26,6 @@
D: Code beautification
N: Daniel Keane
+E: [email protected]
D: Implementation of 'elsif'
+D: Implementation of 'do-while'