Skip to content

Commit

Permalink
Perlito5 - perl6 - refactor_range_operator wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Oct 16, 2013
1 parent c022193 commit 794f076
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions perlito5.pl
Expand Up @@ -12289,6 +12289,14 @@ package Perlito5::Perl6::TreeGrammar;
# use Data::Dumper
# use strict
# use Perlito5::TreeGrammar
sub Perlito5::Perl6::TreeGrammar::refactor_range_operator {
die('Unimplemented');
my($class, $in) = @_;
Perlito5::TreeGrammar::render(['And' => ['Lookup' => 'code', ['Value' => 'infix:<..>']]->['Lookup' => 'arguments', ['And' => ['Index' => 0, ['And' => ['Ref' => 'Perlito5::AST::Val::Int']->['Lookup' => 'int', ['Value' => 0]]]], ['Index' => 1, ['Action' => sub {
$in{'name'} = 'p6:prefix:<^>';
shift(@{$in->{'arguments'}})
}]]]]], $in)
}
sub Perlito5::Perl6::TreeGrammar::refactor_while_glob {
my($class, $in) = @_;
Perlito5::TreeGrammar::render(['Ref' => 'Perlito5::AST::While', ['Lookup' => 'cond', ['And' => ['Ref' => 'Perlito5::AST::Apply'], ['Lookup' => 'code', ['Value' => 'glob']], ['Action' => sub {
Expand Down
36 changes: 36 additions & 0 deletions src5/lib/Perlito5/Perl6/TreeGrammar.pm
Expand Up @@ -3,6 +3,42 @@ use Data::Dumper;
use strict;
use Perlito5::TreeGrammar;

sub refactor_range_operator {
...
my ($class, $in) = @_;
Perlito5::TreeGrammar::render(
[ And => [ Lookup => 'code', [ Value => 'infix:<..>' ] ]
[ Lookup => 'arguments',
[ And => [ Index => 0, [ And => [ Ref => 'Perlito5::AST::Val::Int' ]
[ Lookup => 'int', [ Value => 0 ] ]
]
], # first argument is 0
[ Index => 1,
# TODO 0..$#num to @num.keys
[ Action => sub {
$in{name} = 'p6:prefix:<^>';
shift @{ $in->{arguments} };
}
],
],
]
]
],
$in
);

# 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)
# }

}

sub refactor_while_glob {
my ($class, $in) = @_;
Perlito5::TreeGrammar::render(
Expand Down

0 comments on commit 794f076

Please sign in to comment.