Skip to content

Commit 674c046

Browse files
committed
Perlito5 - perl6 - refator "while <>" to "for lines"
1 parent 3ce38e5 commit 674c046

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

perlito5.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12289,6 +12289,12 @@ package Perlito5::Perl6::TreeGrammar;
1228912289
# use Data::Dumper
1229012290
# use strict
1229112291
# use Perlito5::TreeGrammar
12292+
sub Perlito5::Perl6::TreeGrammar::refactor_while_glob {
12293+
my($class, $in) = @_;
12294+
Perlito5::TreeGrammar::render(['Ref' => 'Perlito5::AST::While', ['Lookup' => 'cond', ['And' => ['Ref' => 'Perlito5::AST::Apply'], ['Lookup' => 'code', ['Value' => 'glob']], ['Action' => sub {
12295+
bless($in, 'Perlito5::AST::For')
12296+
}]]]], $in)
12297+
}
1229212298
sub Perlito5::Perl6::TreeGrammar::refactor_sub_arguments {
1229312299
my($class, $in) = @_;
1229412300
my($rule, $result);
@@ -12755,6 +12761,10 @@ package Perlito5::AST::While;
1275512761
{
1275612762
sub Perlito5::AST::While::emit_perl6 {
1275712763
my $self = $_[0];
12764+
Perlito5::Perl6::TreeGrammar->refactor_while_glob($self);
12765+
if (ref($self) ne 'Perlito5::AST::While') {
12766+
return($self->emit_perl6())
12767+
}
1275812768
my @out;
1275912769
push(@out, ['label' => $self->{'label'}])
1276012770
if $self->{'label'};

src5/lib/Perlito5/Perl6/Emitter.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ package Perlito5::AST::While;
573573
{
574574
sub emit_perl6 {
575575
my $self = $_[0];
576+
577+
Perlito5::Perl6::TreeGrammar->refactor_while_glob($self);
578+
if (ref($self) ne 'Perlito5::AST::While') {
579+
# the node was refactored into something else
580+
return $self->emit_perl6();
581+
}
582+
576583
my @out;
577584
push @out, [ label => $self->{label} ]
578585
if $self->{label};

src5/lib/Perlito5/Perl6/TreeGrammar.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ use Data::Dumper;
33
use strict;
44
use Perlito5::TreeGrammar;
55

6+
sub refactor_while_glob {
7+
my ($class, $in) = @_;
8+
Perlito5::TreeGrammar::render(
9+
[ Ref => 'Perlito5::AST::While',
10+
[ Lookup => 'cond',
11+
[ And => [ Ref => 'Perlito5::AST::Apply' ],
12+
[ Lookup => 'code', [ Value => 'glob' ] ],
13+
[ Action => sub { bless $in, 'Perlito5::AST::For' } ]
14+
]
15+
]
16+
],
17+
$in
18+
);
19+
}
20+
621
sub refactor_sub_arguments {
722
my ($class, $in) = @_;
823
my ( $rule, $result );

0 commit comments

Comments
 (0)