3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

Factoids: improve nested selectors

This commit is contained in:
Pragmatic Software 2020-06-07 15:22:48 -07:00
parent b0789099df
commit 5676d6f13b

View File

@ -535,8 +535,9 @@ sub make_list {
my ($self, $context, $extracted, $settings, %opts) = @_; my ($self, $context, $extracted, $settings, %opts) = @_;
if ($extracted =~ /(.*?)(?<!\\)%\s*\(.*\)/) { if ($extracted =~ /(.*?)(?<!\\)%\s*\(.*\)/) {
$opts{nested} = 1; $opts{nested}++;
$extracted = $self->expand_factoid_selectors($context, $extracted, %opts); $extracted = $self->expand_factoid_selectors($context, $extracted, %opts);
$opts{nested}--;
} }
my @list; my @list;
@ -544,9 +545,7 @@ sub make_list {
$item =~ s/^\s+|\s+$//g; $item =~ s/^\s+|\s+$//g;
$item =~ s/\\\|/|/g; $item =~ s/\\\|/|/g;
my @items = $self->expand_factoid_vars($context, $item, %opts);
foreach $item (@items) {
if ($settings->{'uc'}) { $item = uc $item; } if ($settings->{'uc'}) { $item = uc $item; }
if ($settings->{'lc'}) { $item = lc $item; } if ($settings->{'lc'}) { $item = lc $item; }
@ -559,9 +558,8 @@ sub make_list {
} }
if ($settings->{'json'}) { $item = $self->escape_json($item); } if ($settings->{'json'}) { $item = $self->escape_json($item); }
}
push @list, @items; push @list, $item;
} }
if ($settings->{'unique'}) { if ($settings->{'unique'}) {
@ -584,21 +582,9 @@ sub make_list {
sub select_item { sub select_item {
my ($self, $context, $extracted, $modifier, %opts) = @_; my ($self, $context, $extracted, $modifier, %opts) = @_;
my %default_opts = (
nested => 0,
);
%opts = (%default_opts, %opts);
my %settings = $self->parse_expansion_modifiers($modifier); my %settings = $self->parse_expansion_modifiers($modifier);
if ($opts{nested}) {
my $list = $self->make_list($context, $extracted, \%settings, %opts);
@$list = map { $_ .= $$modifier } @$list;
$$modifier = '';
return join ('|', @$list);
}
my $item; my $item;
if (exists $settings{'index'}) { if (exists $settings{'index'}) {