Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add min/max ** quantifiers. Clean up some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 9, 2009
1 parent 93f11bb commit f4b488a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
8 changes: 8 additions & 0 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -73,6 +73,14 @@ method quantifier:sym<?>($/) {
make $past;
}

method quantifier:sym<**>($/) {
my $past := $<quantmod>.ast;
$past.min(+$<min>);
if ! $<max> { $past.max(+$<min>); }
elsif $<max>[0] ne '*' { $past.max(+$<max>[0]); }
make $past;
}

method quantmod($/) {
my $past := PAST::Regex.new( :pasttype('quant') );
my $str := ~$/;
Expand Down
7 changes: 7 additions & 0 deletions src/Regex/P6Regex/Grammar.pm
Expand Up @@ -43,6 +43,13 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token quantifier:sym<*> { $<sym>=['*'] <quantmod> {*} }
token quantifier:sym<+> { $<sym>=['+'] <quantmod> {*} }
token quantifier:sym<?> { $<sym>=['?'] <quantmod> {*} }
token quantifier:sym<**> {
$<sym>=['**'] <quantmod>
[
| $<min>=[\d+] [ '..' $<max>=[\d+|'*'] ]?
]
{*}
}

token quantmod { ':'? [ '?' | '!' | '+' ]? {*} }

Expand Down
8 changes: 4 additions & 4 deletions t/p6regex/rx_charclass
Expand Up @@ -3,12 +3,12 @@
# todo :pugs<feature>
<[ z ]> abc def n character class ignores ws
# todo :pugs<feature>
<[dcb]>**{3} abcdef y repeated character class
<[dcb]>**3 abcdef y repeated character class
^<[a]> abcdef y anchored character class
<-[e]> abcdef y negated character class
^<[a]>? abcdef y anchored optional character class
<-[e]>? abcdef y negated optional character class
<-[dcb]>**{3} abcdef n repeated negated character class
<-[dcb]>**3 abcdef n repeated negated character class
^<-[e]> abcdef y anchored negated character class
^<-[a]> abcdef n anchored negated character class
<[b..d]> abcdef y character range
Expand Down Expand Up @@ -45,9 +45,9 @@
^\><[<]> >< y lt character class
^<[>]>\< >< y gt character class
# todo :pugs<feature>
^<[><]>**{2} >< y gt, lt character class
^<[><]>**2 >< y gt, lt character class
# todo :pugs<feature>
^<[<>]>**{2} >< y lt, gt character class
^<[<>]>**2 >< y lt, gt character class
^<-[><]> >< n not gt, lt character class
^<-[<>]> >< n not lt, gt character class
'... --- ...' ... --- ... y literal match (\')
Expand Down
21 changes: 0 additions & 21 deletions t/p6regex/rx_quantifiers
Expand Up @@ -160,27 +160,6 @@ xa?:a xay n ques cut 1
:ratchet xa?!a xay /<xa @ 0> ques ratchet greedy 1


## Quantifier closure
.**{2} a n only one character
.**{2} ab y two characters
a**{2} foobar n only one "a" character
a**{2} baabaa y two "a" characters
a**{0..4} bbbbbbb y no "a" characters
a**{2..4} bababab n not two consecutive "a" characters
a**{2..4} baabbbb y two "a" characters
a**{2..4} baaabbb y three "a" characters
a**{2..4} baaaabb y four "a" characters
a**{2..4} baaaaaa y four "a" characters
a**{2..*} baaaaaa y six "a" characters
a**?{2..*} baaaaaa y two "a" characters (non-greedy)
a**:?{2..*} baaaaaa y two "a" characters (non-greedy)
a**!{2..*} baaaaaa y six "a" characters (explicit greed)
a**:!{2..*} baaaaaa y six "a" characters (explicit greed)
a**?{2..4} baaabbb y two "a" characters (non-greedy)
a**:?{2..4} baaabbb y two "a" characters (non-greedy)
a**!{2..4} baaabbb y three "a" characters (explicit greed)
a**:!{2..4} baaabbb y three "a" characters (explicit greed)

## Quantifier bare range
.**2 a n only one character
.**2 ab y two characters
Expand Down

0 comments on commit f4b488a

Please sign in to comment.