aboutsummaryrefslogtreecommitdiffstats
path: root/xmpt
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2017-11-16 16:55:39 +0000
committerBrian Cully <bjc@kublai.com>2017-11-16 16:55:39 +0000
commit7ad6420a0344a66328855777d99dd5d78898b3c7 (patch)
treee0a539c5088de2d329ab7ad3fa1d38c4184837a6 /xmpt
parent747266e88f64a9ebfbad5aa4c15244ef121b70cf (diff)
downloadxmpt-7ad6420a0344a66328855777d99dd5d78898b3c7.tar.gz
xmpt-7ad6420a0344a66328855777d99dd5d78898b3c7.zip
Use named capture groups for thunks in match step.
This allows the use of normal capture groups in templates without the use of the ?: modifier.
Diffstat (limited to 'xmpt')
-rwxr-xr-xxmpt12
1 files changed, 7 insertions, 5 deletions
diff --git a/xmpt b/xmpt
index f23a3b2..b422e2d 100755
--- a/xmpt
+++ b/xmpt
@@ -194,6 +194,7 @@ sub do_send {
sub do_recv {
my $name = shift;
my (@reparts, @thunks);
+ my $i = 0;
foreach my $plan (@_) {
# Text is matched explicitly, thunks are treated as wildcards,
# with the match sent as an argument.
@@ -201,8 +202,9 @@ sub do_recv {
my $t = $plan->[1]->();
push @reparts, $t;
} else {
- push @reparts, "(.*)";
+ push @reparts, "(?<thunk$i>.*)";
push @thunks, $plan->[1];
+ $i++;
}
}
my $re = join '', @reparts;
@@ -223,11 +225,11 @@ sub do_recv {
die "SIGPIPE received from '@ARGV' while matching in $name step.\n";
};
alarm $timeout;
- my @matches;
+ my %matches;
while (1) {
- @matches = ($readbuf =~ /$re/);
- if (@matches >= @thunks) {
+ if ($readbuf =~ /$re/) {
$readbuf = $';
+ %matches = %+;
last;
}
my $r;
@@ -240,7 +242,7 @@ sub do_recv {
alarm 0;
for (my $i = 0; $i < @thunks; $i++) {
- $thunks[$i]->($matches[$i]);
+ $thunks[$i]->($matches{"thunk$i"});
}
}