Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - perl6 - sub refactoring - check args fix
  • Loading branch information
fglock committed Oct 15, 2013
1 parent a3b2e64 commit 9863afb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion perlito5.pl
Expand Up @@ -12320,8 +12320,11 @@ sub Perlito5::Perl6::TreeGrammar::operator_eq {
sub Perlito5::Perl6::TreeGrammar::my_var {
['Ref' => 'Perlito5::AST::Decl', ['And' => ['Lookup' => 'decl', ['Value' => 'my']], (@_ ? ['Progn' => @_] : ())]]
}
sub Perlito5::Perl6::TreeGrammar::var_is_at {
['Ref' => 'Perlito5::AST::Var', ['And' => ['Lookup' => 'sigil', ['Value' => '@']], ['Lookup' => 'name', ['Value' => '_']], (@_ ? ['Progn' => @_] : ())]]
}
sub Perlito5::Perl6::TreeGrammar::shift_arg {
['Ref' => 'Perlito5::AST::Apply', ['And' => ['Lookup' => 'code', ['Value' => 'shift']], (@_ ? ['Progn' => @_] : ())]]
['Ref' => 'Perlito5::AST::Apply', ['And' => ['Lookup' => 'code', ['Value' => 'shift']], ['Or' => ['Lookup' => 'arguments', ['Not' => ['Index' => 0]]], ['Lookup' => 'arguments', ['Index' => 0, var_is_at()]]], (@_ ? ['Progn' => @_] : ())]]
}
1;
package main;
Expand Down
25 changes: 20 additions & 5 deletions src5/lib/Perlito5/Perl6/TreeGrammar.pm
Expand Up @@ -84,13 +84,28 @@ sub my_var {
];
}

sub var_is_at {
[ Ref => 'Perlito5::AST::Var',
[ And => [ Lookup => 'sigil', [ Value => '@' ] ],
[ Lookup => 'name', [ Value => '_' ] ],
( @_ ? [ Progn => @_ ] : () )
]
];
}

sub shift_arg {
[ Ref => 'Perlito5::AST::Apply',
[ And => [ Lookup => 'code', [ Value => 'shift' ] ],

# TODO - bareword => 1, arguments => [], namespace => ''
# or arguments => [ @_ ]
( @_ ? [ Progn => @_ ] : () )
[ And => [ Lookup => 'code', [ Value => 'shift' ] ],
[ Or => [ Lookup => 'arguments',
[ Not => [ Index => 0 ] ] # arg list is empty
],
[ Lookup => 'arguments',
[ Index => 0,
var_is_at() # arg is @_
]
],
],
( @_ ? [ Progn => @_ ] : () )
]
];
}
Expand Down

0 comments on commit 9863afb

Please sign in to comment.