mirror of
https://github.com/pragma-/pbot.git
synced 2025-05-03 13:17:33 +02:00
Extract nested command substitutions and pipes
This commit is contained in:
parent
35aeb6985f
commit
b2273d32fb
@ -166,7 +166,6 @@ sub process_line {
|
|||||||
last if not defined $extracted;
|
last if not defined $extracted;
|
||||||
$extracted =~ s/^\{\s*//;
|
$extracted =~ s/^\{\s*//;
|
||||||
$extracted =~ s/\s*\}$//;
|
$extracted =~ s/\s*\}$//;
|
||||||
$self->{pbot}->{logger}->log("Extracted embedded command [$extracted]\n");
|
|
||||||
push @commands, $extracted;
|
push @commands, $extracted;
|
||||||
$embedded = 1;
|
$embedded = 1;
|
||||||
}
|
}
|
||||||
@ -251,23 +250,32 @@ sub interpret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# parse out a substituted command
|
# parse out a substituted command
|
||||||
if (defined $arguments && $arguments =~ s/(?<!\\)&\{\s*([^}]+)\}/&{subcmd}/) {
|
if (defined $arguments && $arguments =~ m/(?<!\\)&\{/) {
|
||||||
my $command = $1;
|
my ($command) = extract_codeblock $arguments, '{}', '(?s).*?(?<!\\\\)&';
|
||||||
push @{$stuff->{subcmd}}, "$keyword $arguments";
|
|
||||||
$stuff->{command} = $command;
|
if (defined $command) {
|
||||||
my $result = $self->interpret($stuff);
|
$arguments =~ s/&\Q$command\E/&{subcmd}/;
|
||||||
$stuff->{result} = $result;
|
|
||||||
return $result;
|
$command =~ s/^\{\s*//;
|
||||||
|
$command =~ s/\s*\}$//;
|
||||||
|
|
||||||
|
push @{$stuff->{subcmd}}, "$keyword $arguments";
|
||||||
|
$stuff->{command} = $command;
|
||||||
|
$stuff->{result} = $self->interpret($stuff);
|
||||||
|
return $stuff->{result};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# unescape any escaped substituted commands
|
# unescape any escaped substituted commands
|
||||||
$arguments =~ s/\\&\{/&{/g if defined $arguments;
|
$arguments =~ s/\\&\{/&{/g if defined $arguments;
|
||||||
|
|
||||||
# parse out a pipe unless escaped
|
# parse out a pipe
|
||||||
if (defined $arguments && $arguments =~ m/(?<!\\)\|\s*\{\s*[^}]+\}\s*$/) {
|
if (defined $arguments && $arguments =~ m/(?<!\\)\|\s*\{\s*[^}]+\}\s*$/) {
|
||||||
$arguments =~ m/(.*?)\s*(?<!\\)\|\s*\{\s*([^}]+)\}(.*)/s;
|
my ($pipe, $rest, $args) = extract_codeblock $arguments, '{}', '(?s).*?(?<!\\\\)\|\s*';
|
||||||
my ($args, $pipe, $rest) = ($1, $2, $3);
|
|
||||||
$pipe =~ s/\s+$//;
|
$pipe =~ s/^\{\s*//;
|
||||||
|
$pipe =~ s/\s*\}$//;
|
||||||
|
$args =~ s/\s*(?<!\\)\|\s*//;
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("piping: [$args][$pipe][$rest]\n");
|
$self->{pbot}->{logger}->log("piping: [$args][$pipe][$rest]\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user