Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - perl6 - refactor 0..num to ^(num+1)
  • Loading branch information
fglock committed Oct 16, 2013
1 parent 994fbee commit 1e10200
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions perlito5.pl
Expand Up @@ -12658,6 +12658,12 @@ package Perlito5::AST::Apply;
$code = 'infix:<xx>'
}
}
if (($code eq 'print' || $code eq 'say') && !@{$self->{'arguments'}}) {
return(['keyword' => '.' . $code])
}
if ($code eq 'infix:<..>' && ref($self->{'arguments'}->[0]) eq 'Perlito5::AST::Val::Int' && ref($self->{'arguments'}->[1]) eq 'Perlito5::AST::Val::Int' && $self->{'arguments'}->[0]->{'int'} == 0) {
return('^' . ($self->{'arguments'}->[1]->{'int'} + 1))
}
$code = $op_translate{$code}
if $op_translate{$code};
if ($code eq 'prefix:<$>') {
Expand Down
18 changes: 17 additions & 1 deletion src5/lib/Perlito5/Perl6/Emitter.pm
Expand Up @@ -425,14 +425,30 @@ package Perlito5::AST::Apply;
# TODO - glob or <> depending on context
return [ apply => '(', [ keyword => 'lines' ], ];
}

if ($code eq 'infix:<x>' ) {
my $arg = $self->{arguments}->[0];
if ( ref($arg) eq 'Perlito5::AST::Apply' && $arg->{code} eq 'circumfix:<( )>') {
# ($v) x $i
$code = 'infix:<xx>';
}
}
if ( ( $code eq 'print'
|| $code eq 'say'
)
&& !@{$self->{arguments}}
)
{
return [ keyword => '.' . $code ];
}
if ( $code eq 'infix:<..>'
&& ref($self->{arguments}[0]) eq 'Perlito5::AST::Val::Int'
&& ref($self->{arguments}[1]) eq 'Perlito5::AST::Val::Int'
&& $self->{arguments}[0]{int} == 0
)
{
# TODO - add formatting tags
return '^' . ($self->{arguments}[1]{int} + 1)
}

$code = $op_translate{$code} if $op_translate{$code};

Expand Down

0 comments on commit 1e10200

Please sign in to comment.