Skip to content

Commit

Permalink
P6regex: Switch ?-quantifier to be an item quantifier instead of a li…
Browse files Browse the repository at this point in the history
…st quantifier.

In other words, using ? on a capturing expression no longer produces
a list of captures; it's a single capture (or Nil/nonexistent).
  • Loading branch information
pmichaud committed Apr 30, 2013
1 parent 16fa719 commit b48b5c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/QRegex/P6Regex/Actions.nqp
Expand Up @@ -119,7 +119,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
}

method quantifier:sym<?>($/) {
my $qast := QAST::Regex.new( :rxtype<quant>, :min(0), :max(1), :node($/) );
my $qast := QAST::Regex.new( :rxtype<quant>, :subtype<item>, :min(0), :max(1), :node($/) );
make backmod($qast, $<backmod>);
}

Expand Down Expand Up @@ -633,7 +633,8 @@ class QRegex::P6Regex::Actions is HLL::Actions {
}
elsif $rxtype eq 'quant' {
my %astcap := capnames($ast[0], $count);
for %astcap { %capnames{$_} := 2 }
my $ilist := ($ast.subtype eq 'item');
for %astcap { %capnames{$_.key} := $ilist ?? $_.value !! 2 }
$count := %astcap{''};
}
%capnames{''} := $count;
Expand Down
2 changes: 1 addition & 1 deletion t/qregex/01-qregex.t
Expand Up @@ -5,7 +5,7 @@ use QRegex;

my @files := [
'rx_captures',
# 'rx_qcaps',
'rx_qcaps',
'rx_basic',
'rx_quantifiers',
'rx_metachars',
Expand Down
8 changes: 4 additions & 4 deletions t/qregex/rx_captures
Expand Up @@ -60,9 +60,9 @@ $1=[ (.) (.) (.) ] (.) abcdefg <mob[5]: d @ 3> perl5 numbered captures $1
$<key>=<alpha> 12ab34 <mob<key>: a @ 2> alias capture
<key=alpha> 12ab34 <mob<key>: a @ 2> alias capture

:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two three <mob<w3>[0]: three @ 8> RT #107254
:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two three <mob<w2>[0]: two @ 4> RT #107254
:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two <mob<w2>[0]: two @ 4> RT #107254
:s :r $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two <mob<w2>[0]: two @ 4> RT #107254
:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two three <mob<w3>: three @ 8> RT #107254
:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two three <mob<w2>: two @ 4> RT #107254
:s $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two <mob<w2>: two @ 4> RT #107254
:s :r $<w1>=(\w+) $<w2>=(\w+)? $<w3>=(\w+)? one two <mob<w2>: two @ 4> RT #107254

## vim: noexpandtab tabstop=4 shiftwidth=4

0 comments on commit b48b5c3

Please sign in to comment.