Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - perl6 - refator "while <>" to "for lines"
  • Loading branch information
fglock committed Oct 16, 2013
1 parent 3ce38e5 commit 674c046
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions perlito5.pl
Expand Up @@ -12289,6 +12289,12 @@ package Perlito5::Perl6::TreeGrammar;
# use Data::Dumper
# use strict
# use Perlito5::TreeGrammar
sub Perlito5::Perl6::TreeGrammar::refactor_while_glob {
my($class, $in) = @_;
Perlito5::TreeGrammar::render(['Ref' => 'Perlito5::AST::While', ['Lookup' => 'cond', ['And' => ['Ref' => 'Perlito5::AST::Apply'], ['Lookup' => 'code', ['Value' => 'glob']], ['Action' => sub {
bless($in, 'Perlito5::AST::For')
}]]]], $in)
}
sub Perlito5::Perl6::TreeGrammar::refactor_sub_arguments {
my($class, $in) = @_;
my($rule, $result);
Expand Down Expand Up @@ -12755,6 +12761,10 @@ package Perlito5::AST::While;
{
sub Perlito5::AST::While::emit_perl6 {
my $self = $_[0];
Perlito5::Perl6::TreeGrammar->refactor_while_glob($self);
if (ref($self) ne 'Perlito5::AST::While') {
return($self->emit_perl6())
}
my @out;
push(@out, ['label' => $self->{'label'}])
if $self->{'label'};
Expand Down
7 changes: 7 additions & 0 deletions src5/lib/Perlito5/Perl6/Emitter.pm
Expand Up @@ -573,6 +573,13 @@ package Perlito5::AST::While;
{
sub emit_perl6 {
my $self = $_[0];

Perlito5::Perl6::TreeGrammar->refactor_while_glob($self);
if (ref($self) ne 'Perlito5::AST::While') {
# the node was refactored into something else
return $self->emit_perl6();
}

my @out;
push @out, [ label => $self->{label} ]
if $self->{label};
Expand Down
15 changes: 15 additions & 0 deletions src5/lib/Perlito5/Perl6/TreeGrammar.pm
Expand Up @@ -3,6 +3,21 @@ use Data::Dumper;
use strict;
use Perlito5::TreeGrammar;

sub refactor_while_glob {
my ($class, $in) = @_;
Perlito5::TreeGrammar::render(
[ Ref => 'Perlito5::AST::While',
[ Lookup => 'cond',
[ And => [ Ref => 'Perlito5::AST::Apply' ],
[ Lookup => 'code', [ Value => 'glob' ] ],
[ Action => sub { bless $in, 'Perlito5::AST::For' } ]
]
]
],
$in
);
}

sub refactor_sub_arguments {
my ($class, $in) = @_;
my ( $rule, $result );
Expand Down

0 comments on commit 674c046

Please sign in to comment.