diff options
author | Brian Cully <bjc@kublai.com> | 2017-11-16 16:55:39 +0000 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2017-11-16 16:55:39 +0000 |
commit | 7ad6420a0344a66328855777d99dd5d78898b3c7 (patch) | |
tree | e0a539c5088de2d329ab7ad3fa1d38c4184837a6 /xmpt | |
parent | 747266e88f64a9ebfbad5aa4c15244ef121b70cf (diff) | |
download | xmpt-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-x | xmpt | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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"}); } } |