Skip to content

Commit 22b4fa8

Browse files
committed
Add subcaptures.
1 parent ec4c7a3 commit 22b4fa8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/QAST/Compiler.nqp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,28 @@ class QAST::Compiler is HLL::Compiler {
323323
$ops;
324324
}
325325

326+
method subcapture($node) {
327+
my $ops := self.post_new('Ops', :result(%*REG<cur>));
328+
my $prefix := self.unique('rxcap');
329+
my $donelabel := self.post_new('Label', :result($prefix ~ '_done'));
330+
my $faillabel := self.post_new('Label', :result($prefix ~ '_fail'));
331+
my $name := $*PASTCOMPILER.as_post($node.name, :rtype<*>);
332+
self.regex_mark($ops, $faillabel, %*REG<pos>, 0);
333+
$ops.push(self.regex_post($node[0]));
334+
self.regex_peek($ops, $faillabel, '$I11');
335+
$ops.push($name);
336+
$ops.push_pirop('repr_bind_attr_int', %*REG<cur>, %*REG<curclass>, '"$!pos"', '$I11');
337+
$ops.push_pirop('callmethod', '"!cursor_start"', %*REG<cur>, :result<$P11>);
338+
$ops.push_pirop('callmethod', '"!cursor_pass"', '$P11', %*REG<pos>);
339+
$ops.push_pirop('callmethod', '"!cursor_capture"', %*REG<cur>,
340+
'$P11', $name, :result(%*REG<caps>));
341+
$ops.push_pirop('goto', $donelabel);
342+
$ops.push($faillabel);
343+
$ops.push_pirop('goto', %*REG<fail>);
344+
$ops.push($donelabel);
345+
$ops;
346+
}
347+
326348
method subrule($node) {
327349
my $ops := self.post_new('Ops', :result(%*REG<cur>));
328350
my $name := $*PASTCOMPILER.as_post($node.name, :rtype<*>);

src/QRegex/P6Regex/Actions.nqp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ class QRegex::P6Regex::Actions is HLL::Actions {
383383
%capnames{$_} := 1;
384384
}
385385
}
386+
elsif $rxtype eq 'subcapture' {
387+
for nqp::split(' ', $ast.name) {
388+
if $_ eq '0' || $_ > 0 { $count := $_ + 1; }
389+
%capnames{$_} := 1;
390+
}
391+
my %x := capnames($ast[0], $count);
392+
for %x { %capnames{$_.key} := +%capnames{$_.key} + %x{$_.key} }
393+
$count := %x{''};
394+
}
386395
elsif $rxtype eq 'quant' {
387396
my %astcap := capnames($ast[0], $count);
388397
for %astcap { %capnames{$_} := 2 }

0 commit comments

Comments
 (0)