Skip to content

Commit 1e10200

Browse files
committed
Perlito5 - perl6 - refactor 0..num to ^(num+1)
1 parent 994fbee commit 1e10200

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

perlito5.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12658,6 +12658,12 @@ package Perlito5::AST::Apply;
1265812658
$code = 'infix:<xx>'
1265912659
}
1266012660
}
12661+
if (($code eq 'print' || $code eq 'say') && !@{$self->{'arguments'}}) {
12662+
return(['keyword' => '.' . $code])
12663+
}
12664+
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) {
12665+
return('^' . ($self->{'arguments'}->[1]->{'int'} + 1))
12666+
}
1266112667
$code = $op_translate{$code}
1266212668
if $op_translate{$code};
1266312669
if ($code eq 'prefix:<$>') {

src5/lib/Perlito5/Perl6/Emitter.pm

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,30 @@ package Perlito5::AST::Apply;
425425
# TODO - glob or <> depending on context
426426
return [ apply => '(', [ keyword => 'lines' ], ];
427427
}
428-
429428
if ($code eq 'infix:<x>' ) {
430429
my $arg = $self->{arguments}->[0];
431430
if ( ref($arg) eq 'Perlito5::AST::Apply' && $arg->{code} eq 'circumfix:<( )>') {
432431
# ($v) x $i
433432
$code = 'infix:<xx>';
434433
}
435434
}
435+
if ( ( $code eq 'print'
436+
|| $code eq 'say'
437+
)
438+
&& !@{$self->{arguments}}
439+
)
440+
{
441+
return [ keyword => '.' . $code ];
442+
}
443+
if ( $code eq 'infix:<..>'
444+
&& ref($self->{arguments}[0]) eq 'Perlito5::AST::Val::Int'
445+
&& ref($self->{arguments}[1]) eq 'Perlito5::AST::Val::Int'
446+
&& $self->{arguments}[0]{int} == 0
447+
)
448+
{
449+
# TODO - add formatting tags
450+
return '^' . ($self->{arguments}[1]{int} + 1)
451+
}
436452

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

0 commit comments

Comments
 (0)