Skip to content

Commit

Permalink
close #45
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
balajirama committed Jun 13, 2019
1 parent 63004b3 commit 0094e0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -5,7 +5,7 @@ Revision history for {{$dist->name}}
- Import functions from String::Util, Scalar::Util, String::Util::Match, String::Util::Range, and String::Index.
These can be accessed inside the ExAWK string rules directly (#44)
- Added new methods to Text::Parser called add_rule to create rules (#37), and clear_rules to delete rules (#40)
- Rules support range shortcuts like ${3+} (#39)
- Rules support range shortcuts like ${3+}, @{2+}, and \@{3+} (#39), (#45)
- Added new method join_range available when auto_split => 1 (#38)

0.920 2019-06-09 19:48:42-07:00 America/Los_Angeles
Expand Down
30 changes: 15 additions & 15 deletions lib/Text/Parser/Rule.pm
Expand Up @@ -70,16 +70,16 @@ sub _set_condition {
sub _get_min_req_fields {
my $str = shift;
my @indx
= $str =~ /\$([0-9]+)|\$[{]([-][0-9]+)[}]|\$[{]([-]?[0-9]+)[+][}]/g;
= $str =~ /\$([0-9]+)|\$[{]([-][0-9]+)[}]|[$@][{]([-]?[0-9]+)[+][}]/g;
my @inds = sort { $b <=> $a } ( grep { defined $_ } @indx );
return 0 if not @inds;
( $inds[0] >= -$inds[-1] ) ? $inds[0] : -$inds[-1];
}

my $SUB_BEGIN = 'sub {
my $this = shift;
return if not defined $this->this_line; # condition usually caught earlier, but to be safe
local $_ = $this->this_line;
return if not defined $this->this_line;
';

my $SUB_END = '
Expand All @@ -92,25 +92,25 @@ sub _gen_sub_str {
}

sub _replace_awk_vars {
my $str = shift;
$str =~ s/\$0/\$this->this_line/g;
$str = _replace_positional_indicators($str);
$str = _replace_range_shortcut($str);
return $str;
local $_ = shift;
_replace_positional_indicators();
_replace_range_shortcut();
return $_;
}

sub _replace_positional_indicators {
my $str = shift;
$str =~ s/\$[{]([-][0-9]+)[}]/\$this->field($1)/g;
$str =~ s/\$([0-9]+)/\$this->field($1 - 1)/g;
return $str;
s/\$0/\$this->this_line/g;
s/\$[{]([-][0-9]+)[}]/\$this->field($1)/g;
s/\$([0-9]+)/\$this->field($1-1)/g;
}

sub _replace_range_shortcut {
my $str = shift;
$str =~ s/\$[{]([-][0-9]+)[+][}]/\$this->join_range($1)/g;
$str =~ s/\$[{]([0-9]+)[+][}]/\$this->join_range($1-1)/g;
return $str;
s/\$[{]([-][0-9]+)[+][}]/\$this->join_range($1)/g;
s/\$[{]([0-9]+)[+][}]/\$this->join_range($1-1)/g;
s/\\\@[{]([-][0-9]+)[+][}]/[\$this->field_range($1)]/g;
s/\\\@[{]([0-9]+)[+][}]/[\$this->field_range($1-1)]/g;
s/\@[{]([-][0-9]+)[+][}]/\$this->field_range($1)/g;
s/\@[{]([0-9]+)[+][}]/\$this->field_range($1-1)/g;
}

has _cond_sub_str => (
Expand Down

0 comments on commit 0094e0c

Please sign in to comment.