So, since Rakudo's current grammar pretty much matches what STD.pm has here, I'd prefer that we figure out how STD.pm is handling empty statements and do that.

Thanks again!

Pm

As far as I can tell, STD.pm handles this problem in "token statement", as shown below. If you modify the statement rule in grammar.pg the same way and make a small change to actions.pm, parrot/perl6 seems to handle empty ; statements fine and passes the small, included, test suite. The revised patches are attached.

token statement {
   ...
   | <?before ';'> {*}                                         #= null
   ...
}
Index: src/parser/grammar.pg
===================================================================
--- src/parser/grammar.pg       (revision 28329)
+++ src/parser/grammar.pg       (working copy)
@@ -203,6 +203,7 @@
             {*}                                  #= statement_mod_cond
         || {*}                                   #= expr
         ]
+    | <?before ';'> {*}                          #= null
 }
 
 rule statement_control {
Index: src/parser/actions.pm
===================================================================
--- src/parser/actions.pm       (revision 28329)
+++ src/parser/actions.pm       (working copy)
@@ -111,6 +111,9 @@
     if $key eq 'statement_control' {
         $past := $( $<statement_control> );
     }
+    elsif $key eq 'null' {
+        $past := PAST::Stmts.new();  # empty stmts seem eliminated by TGE
+    }    
     else {
         my $expr := $( $<expr> );
         if $expr.WHAT() eq 'Block' && !$expr.blocktype() {
Index: t/spectest_regression.data
===================================================================
--- t/spectest_regression.data  (revision 28329)
+++ t/spectest_regression.data  (working copy)
@@ -15,6 +15,7 @@
 S03-operators/not.t                             # pure
 S03-operators/relational.t                      # pure
 S03-operators/true.t                            # pure
+S04-statements/terminator.t                     # pure
 S04-statements/try.t
 S04-statements/until.t                          # pure
 S04-statements/while.t
use v6;

use Test;

plan 9;

# L<S04/"Statement parsing"/"statement termination">

# the 'empty statement' case responsible for the creation of this test file
eval_lives_ok(';', 'empty statement');

eval_lives_ok('my $x = 2', 'simple statement no semi');
eval_lives_ok('my $x =
9', 'simple statement on two lines no semi');
eval_lives_ok('my $x = 2;', 'simple statement with semi');
eval_lives_ok('{my $x = 2}', 'end of closure terminator');
eval_lives_ok('{my $x =
2;}', 'double terminator');
eval_lives_ok(';my $x = 2;{my $x = 2;;};', 'extra terminators');

eval_dies_ok('{my $x = 2;', 'open closure');
eval_dies_ok('my $x = ', 'incomplete expression');

Reply via email to