mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 03:02:47 +01:00
Interpreter: improve parsing of embedded commands
This commit is contained in:
parent
bd6af472e8
commit
bc05915905
@ -992,10 +992,16 @@ sub add_botcmd_to_command_queue($self, $channel, $command, $delay = 0) {
|
|||||||
# optional prefix may be or begin with a character group.
|
# optional prefix may be or begin with a character group.
|
||||||
sub extract_bracketed($self, $string, $open_bracket = '{', $close_bracket = '}', $optional_prefix = '', $allow_whitespace = 0) {
|
sub extract_bracketed($self, $string, $open_bracket = '{', $close_bracket = '}', $optional_prefix = '', $allow_whitespace = 0) {
|
||||||
my @prefix_group;
|
my @prefix_group;
|
||||||
|
|
||||||
if ($optional_prefix =~ s/^\[(.*?)\]//) { @prefix_group = split //, $1; }
|
if ($optional_prefix =~ s/^\[(.*?)\]//) { @prefix_group = split //, $1; }
|
||||||
|
|
||||||
my @prefixes = split //, $optional_prefix;
|
my @prefix;
|
||||||
|
my $prefix_max;
|
||||||
|
|
||||||
|
if (!@prefix_group && $optional_prefix ne '""' && $optional_prefix ne "''") {
|
||||||
|
@prefix = split //, $optional_prefix;
|
||||||
|
$prefix_max = length $optional_prefix;
|
||||||
|
}
|
||||||
|
|
||||||
my @opens = split //, $open_bracket;
|
my @opens = split //, $open_bracket;
|
||||||
my @closes = split //, $close_bracket;
|
my @closes = split //, $close_bracket;
|
||||||
|
|
||||||
@ -1015,7 +1021,7 @@ sub extract_bracketed($self, $string, $open_bracket = '{', $close_bracket = '}',
|
|||||||
my $bracket_pos;
|
my $bracket_pos;
|
||||||
my $bracket_level = 0;
|
my $bracket_level = 0;
|
||||||
my $prefix_group_match = @prefix_group ? 0 : 1;
|
my $prefix_group_match = @prefix_group ? 0 : 1;
|
||||||
my $prefix_match = @prefixes ? 0 : 1;
|
my $prefix_match = @prefix ? 0 : 1;
|
||||||
my $match = 0;
|
my $match = 0;
|
||||||
|
|
||||||
my @chars = split //, $string;
|
my @chars = split //, $string;
|
||||||
@ -1058,30 +1064,32 @@ sub extract_bracketed($self, $string, $open_bracket = '{', $close_bracket = '}',
|
|||||||
|
|
||||||
if (not $extracted) {
|
if (not $extracted) {
|
||||||
if ($state eq 'prefixgroup' and @prefix_group and not $extracting) {
|
if ($state eq 'prefixgroup' and @prefix_group and not $extracting) {
|
||||||
|
$prefix_group_match = 0;
|
||||||
foreach my $prefix_ch (@prefix_group) {
|
foreach my $prefix_ch (@prefix_group) {
|
||||||
if ($ch eq $prefix_ch) {
|
if ($ch eq $prefix_ch) {
|
||||||
$prefix_group_match = 1;
|
$prefix_group_match = 1;
|
||||||
$state = 'prefixes';
|
$state = 'openbracket';
|
||||||
last;
|
last;
|
||||||
} else {
|
|
||||||
$prefix_group_match = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next if $prefix_group_match;
|
next if $prefix_group_match;
|
||||||
} elsif ($state eq 'prefixgroup' and not @prefix_group) {
|
} elsif ($state eq 'prefixgroup' and not @prefix_group) {
|
||||||
$state = 'prefixes';
|
$state = 'prefix';
|
||||||
$prefix_index = 0;
|
$prefix_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($state eq 'prefixes') {
|
if ($state eq 'prefix') {
|
||||||
if (@prefixes and $ch eq $prefixes[$prefix_index]) {
|
if (@prefix and $prefix_index < $prefix_max and $ch eq $prefix[$prefix_index]) {
|
||||||
$token .= $ch if $extracting;
|
$token .= $ch if $extracting;
|
||||||
$prefix_match = 1;
|
$prefix_match = 1;
|
||||||
$prefix_index++;
|
$prefix_index++;
|
||||||
|
if ($prefix_index >= $prefix_max) {
|
||||||
$state = 'openbracket';
|
$state = 'openbracket';
|
||||||
|
}
|
||||||
next;
|
next;
|
||||||
} elsif ($state eq 'prefixes' and not @prefixes) {
|
} elsif (@prefix) {
|
||||||
$state = 'openbracket';
|
$prefix_match = 0;
|
||||||
|
$state = 'prefixgroup';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1102,7 +1110,7 @@ sub extract_bracketed($self, $string, $open_bracket = '{', $close_bracket = '}',
|
|||||||
if ($match) {
|
if ($match) {
|
||||||
$state = 'prefixgroup';
|
$state = 'prefixgroup';
|
||||||
$prefix_group_match = 0 unless not @prefix_group;
|
$prefix_group_match = 0 unless not @prefix_group;
|
||||||
$prefix_match = 0 unless not @prefixes;
|
$prefix_match = 0 unless not @prefix;
|
||||||
$match = 0;
|
$match = 0;
|
||||||
$bracket_pos = $i if not $extracting;
|
$bracket_pos = $i if not $extracting;
|
||||||
if ($open_index == @opens) {
|
if ($open_index == @opens) {
|
||||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4672,
|
BUILD_REVISION => 4673,
|
||||||
BUILD_DATE => "2023-05-11",
|
BUILD_DATE => "2023-05-11",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user