Permalink
Browse files

P6regex: Switch ?-quantifier to be an item quantifier instead of a li…

…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 b48b5c3f7033e49e217c3264189094e49842fac4
Showing with 8 additions and 7 deletions.
  1. +3 −2 src/QRegex/P6Regex/Actions.nqp
  2. +1 −1 t/qregex/01-qregex.t
  3. +4 −4 t/qregex/rx_captures
@@ -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>);
}
@@ -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;
View
@@ -5,7 +5,7 @@ use QRegex;
my @files := [
'rx_captures',
-# 'rx_qcaps',
+ 'rx_qcaps',
'rx_basic',
'rx_quantifiers',
'rx_metachars',
View
@@ -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.