Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enable non-capturing groups and named captures
  • Loading branch information
FROGGS committed Aug 19, 2013
1 parent 8733f0e commit 210cd15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/QRegex/P5Regex/Actions.nqp
Expand Up @@ -99,8 +99,20 @@ class QRegex::P5Regex::Actions is HLL::Actions {
);
}

method p5metachar:sym<(? )>($/) {
make $<assertion>.ast;
method p5metachar:sym<(? )>($/) { # like P6's $<name>=[ ... ]
my $qast;
if $<nibbler> {
$qast := QAST::Regex.new( :rxtype<subcapture>, :name(~$<name>),
$<nibbler>.ast, :node($/) );
}
else {
$qast := $<assertion>.ast;
}
make $qast;
}

method p5metachar:sym<(?: )>($/) {
make $<nibbler>.ast;
}

method p5metachar:sym<( )>($/) {
Expand Down
11 changes: 9 additions & 2 deletions src/QRegex/P5Regex/Grammar.nqp
Expand Up @@ -86,6 +86,7 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
proto token p5metachar { <...> }

token p5metachar:sym<quant> {
<![(?]>
<quantifier=p5quantifier>
<.panic: "quantifier quantifies nothing">
}
Expand All @@ -96,9 +97,15 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
'$' <?before \W | $>
}
token p5metachar:sym<(? )> {
'(?' {} <assertion=p5assertion>
[ ')' || <.panic: "Perl 5 regex assertion not terminated by parenthesis"> ]
'(?' <![?]>
[
| <?[<]> '<' $<name>=[<-[>]>+] '>' {} <nibbler>
| <?[']> "'" $<name>=[<-[']>+] "'" {} <nibbler>
| <assertion=p5assertion>
]
[ ')' || <.panic: "Perl 5 named capture group not terminated by parenthesis"> ]
}
token p5metachar:sym<(?: )> { '(?:' {} <nibbler> ')' }
token p5metachar:sym<( )> { '(' {} <nibbler> ')' }
token p5metachar:sym<[ ]> { <?before '['> <cclass> }

Expand Down

0 comments on commit 210cd15

Please sign in to comment.