3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-25 04:02:37 +01:00

Factoids: correct recursive $var expansion

This commit is contained in:
Pragmatic Software 2020-06-12 00:02:32 -07:00
parent 0191a2914b
commit ead2d5d55f

View File

@ -693,9 +693,9 @@ sub expand_factoid_selectors {
my ($article, $trailing) = ($1, $2); my ($article, $trailing) = ($1, $2);
my $fixed_article = select_indefinite_article $item; my $fixed_article = select_indefinite_article $item;
if ($article eq 'A' or $article eq 'AN') { if ($article eq 'AN') {
$fixed_article = uc $fixed_article; $fixed_article = uc $fixed_article;
} elsif ($article eq 'An') { } elsif ($article eq 'An' or $article eq 'A') {
$fixed_article = ucfirst $fixed_article; $fixed_article = ucfirst $fixed_article;
} }
@ -824,15 +824,17 @@ sub expand_factoid_vars {
if (not length $replacement) { if (not length $replacement) {
$result =~ s/\s+$//; $result =~ s/\s+$//;
} else {
$replacement = $self->expand_factoid_vars($context, $replacement, %opts);
} }
if ($result =~ s/\b(a|an)(\s+)$//i) { if ($result =~ s/\b(a|an)(\s+)$//i) {
my ($article, $trailing) = ($1, $2); my ($article, $trailing) = ($1, $2);
my $fixed_article = select_indefinite_article $replacement; my $fixed_article = select_indefinite_article $replacement;
if ($article eq 'A' or $article eq 'AN') { if ($article eq 'AN') {
$fixed_article = uc $fixed_article; $fixed_article = uc $fixed_article;
} elsif ($article eq 'An') { } elsif ($article eq 'An' or $article eq 'A') {
$fixed_article = ucfirst $fixed_article; $fixed_article = ucfirst $fixed_article;
} }
@ -848,14 +850,8 @@ sub expand_factoid_vars {
} }
if ($matches == 0 or $expansions == 0) { if ($matches == 0 or $expansions == 0) {
if (length $rest) {
$rest = $result . $rest;
$result = '';
next;
} else {
last; last;
} }
}
if (not length $rest) { if (not length $rest) {
$rest = $result; $rest = $result;