# New Ticket Created by Ron Schmidt # Please include the string: [perl #55594] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55594 >
Perl 5 allows empty semicolon terminated statements. perl6 currently allows for empty closures but treats a semicolon that follows nothing or whitespace as a syntax error. The attached patch to grammar.pg provides a fix for this discrepancy between perl 5 and perl 6. Also attached is an attempt at a test suite for some statement termination cases. The patch is small and passes "make fulltest" under ubuntu and "make spectest", as well as the parts of "make test" in the perl6 directory, under cygwin. Modifying statementlist this way does not appear to be the most elegant solution to the problem but approaches like [<statement>?<.eat_terminator> ]* seemed to fail with relatively serious errors. The terminator.t test file is vaguely intended for the t/spec/S04-statements/ directory.
Index: t/spectest_regression.data =================================================================== --- t/spectest_regression.data (revision 28227) +++ 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 Index: src/parser/grammar.pg =================================================================== --- src/parser/grammar.pg (revision 28227) +++ src/parser/grammar.pg (working copy) @@ -151,8 +151,10 @@ rule statementlist { - [<statement><.eat_terminator> ]* - {*} + | [ + || ';' + || <statement><.eat_terminator> + ]* {*} } ## The eat_terminator detects when we're at a valid
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');