Skip to content

Commit aff9748

Browse files
committed
Perlito5 - integrate Perlito5/Grammar/Print.pm - indirect syntax for print
1 parent 183a6ee commit aff9748

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src5/lib/Perlito5/Emitter/Token.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ sub closure { $_[0]->{closure} }
264264
sub emit_perl5 {
265265
my $self = $_[0];
266266

267-
'(do { ' . $self->{closure} . '; 1 })'
267+
'(do { '
268+
. '$MATCH->{str} = $str; '
269+
. $self->{closure}
270+
. '; 1 })'
268271
}
269272
sub set_captures_to_array {
270273
my $self = $_[0];

src5/lib/Perlito5/Grammar.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use Perlito5::Grammar::Sigil;
77
use Perlito5::Grammar::Use;
88
use Perlito5::Grammar::Block;
99
use Perlito5::Grammar::Space;
10+
use Perlito5::Grammar::Print;
1011

1112
sub word {
1213
substr( $_[1], $_[2], 1 ) =~ m/\w/

src5/lib/Perlito5/Grammar/Print.pm

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,51 @@ token the_object {
1515
[
1616
<before '$'> <Perlito5::Grammar::Sigil.term_sigil>
1717
<!before '+'>
18-
<.Perlito5::Grammar::Space.opt_ws>
1918
{
2019
$MATCH->{capture} = Perlito5::Match::flat($MATCH->{'Perlito5::Grammar::Sigil.term_sigil'})->[1];
2120
}
2221
|
2322
'{' <Perlito5::Expression.curly_parse> '}'
24-
<.Perlito5::Grammar::Space.opt_ws>
25-
<!before ','>
2623
{
2724
$MATCH->{capture} = Perlito5::Match::flat($MATCH->{'Perlito5::Expression.curly_parse'});
2825
}
2926
|
3027
<typeglob>
31-
<.Perlito5::Grammar::Space.opt_ws>
32-
<!before ','>
3328
{
3429
$MATCH->{capture} = Perlito5::Match::flat($MATCH->{'typeglob'});
3530
}
3631
]
3732

3833
{
39-
my $s = substr($MATCH->{str}, $MATCH->{to}, 1);
40-
if ( $s eq ',' ) {
34+
my $pos = $MATCH->{to};
35+
my $m = Perlito5::Grammar::Space->ws($MATCH->{str}, $pos);
36+
$pos = $m->{to} if $m;
37+
38+
my $s = substr($MATCH->{str}, $pos, 1);
39+
my $s2 = substr($MATCH->{str}, $pos, 2);
40+
41+
# print Perlito5::Dumper::Dumper $MATCH;
42+
# print "after: $MATCH->{capture} $pos '$MATCH->{str}' '$s' '$s2'\n";
43+
44+
if ( $s eq ','
45+
|| $s eq '?'
46+
|| $s2 eq '->'
47+
|| $s eq '['
48+
|| $s eq '{'
49+
|| $s eq '('
50+
)
51+
{
4152
return
4253
}
4354
if ( $s eq '+' ) {
44-
my $m = Perlito5::Grammar::Space->ws($MATCH->{str}, $MATCH->{to} + 1);
55+
my $m = Perlito5::Grammar::Space->ws($MATCH->{str}, $pos + 1);
4556
if ($m) {
4657
return
4758
}
4859
# print "space + non-space\n";
4960
}
5061
else {
51-
my $m = Perlito5::Precedence->op_parse($MATCH->{str}, $MATCH->{to}, 1);
62+
my $m = Perlito5::Precedence->op_parse($MATCH->{str}, $pos, 1);
5263
my $next_op = $m ? Perlito5::Match::flat($m)->[1] : '';
5364
my $is_infix = Perlito5::Precedence::is_fixity_type('infix', $next_op);
5465
# print "is_infix $is_infix '$next_op'\n";

t5/01-perlito/05-for-global.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use feature 'say';
2+
use strict;
3+
4+
say '1..2';
5+
my @a = ( 1, 2 );
6+
for my $v (@a) {
7+
say 'ok ' . $v . ' - loop';
8+
}
9+

0 commit comments

Comments
 (0)