Skip to content

Commit 9863afb

Browse files
committed
Perlito5 - perl6 - sub refactoring - check args fix
1 parent a3b2e64 commit 9863afb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

perlito5.pl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12320,8 +12320,11 @@ sub Perlito5::Perl6::TreeGrammar::operator_eq {
1232012320
sub Perlito5::Perl6::TreeGrammar::my_var {
1232112321
['Ref' => 'Perlito5::AST::Decl', ['And' => ['Lookup' => 'decl', ['Value' => 'my']], (@_ ? ['Progn' => @_] : ())]]
1232212322
}
12323+
sub Perlito5::Perl6::TreeGrammar::var_is_at {
12324+
['Ref' => 'Perlito5::AST::Var', ['And' => ['Lookup' => 'sigil', ['Value' => '@']], ['Lookup' => 'name', ['Value' => '_']], (@_ ? ['Progn' => @_] : ())]]
12325+
}
1232312326
sub Perlito5::Perl6::TreeGrammar::shift_arg {
12324-
['Ref' => 'Perlito5::AST::Apply', ['And' => ['Lookup' => 'code', ['Value' => 'shift']], (@_ ? ['Progn' => @_] : ())]]
12327+
['Ref' => 'Perlito5::AST::Apply', ['And' => ['Lookup' => 'code', ['Value' => 'shift']], ['Or' => ['Lookup' => 'arguments', ['Not' => ['Index' => 0]]], ['Lookup' => 'arguments', ['Index' => 0, var_is_at()]]], (@_ ? ['Progn' => @_] : ())]]
1232512328
}
1232612329
1;
1232712330
package main;

src5/lib/Perlito5/Perl6/TreeGrammar.pm

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,28 @@ sub my_var {
8484
];
8585
}
8686

87+
sub var_is_at {
88+
[ Ref => 'Perlito5::AST::Var',
89+
[ And => [ Lookup => 'sigil', [ Value => '@' ] ],
90+
[ Lookup => 'name', [ Value => '_' ] ],
91+
( @_ ? [ Progn => @_ ] : () )
92+
]
93+
];
94+
}
95+
8796
sub shift_arg {
8897
[ Ref => 'Perlito5::AST::Apply',
89-
[ And => [ Lookup => 'code', [ Value => 'shift' ] ],
90-
91-
# TODO - bareword => 1, arguments => [], namespace => ''
92-
# or arguments => [ @_ ]
93-
( @_ ? [ Progn => @_ ] : () )
98+
[ And => [ Lookup => 'code', [ Value => 'shift' ] ],
99+
[ Or => [ Lookup => 'arguments',
100+
[ Not => [ Index => 0 ] ] # arg list is empty
101+
],
102+
[ Lookup => 'arguments',
103+
[ Index => 0,
104+
var_is_at() # arg is @_
105+
]
106+
],
107+
],
108+
( @_ ? [ Progn => @_ ] : () )
94109
]
95110
];
96111
}

0 commit comments

Comments
 (0)