Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First stab and % and %%.
  • Loading branch information
jnthn committed Nov 18, 2011
1 parent f599448 commit 879321b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/QRegex/P6Regex/Actions.nqp
Expand Up @@ -69,9 +69,24 @@ class QRegex::P6Regex::Actions is HLL::Actions {
$ast.unshift($qast);
$qast := $ast;
}
if $<separator> {
unless $qast.rxtype eq 'quant' {
$/.CURSOR.panic("'" ~ $<separator>[0]<septype> ~
"' many only be used immediately following a quantifier")
}
$qast.push($<separator>[0].ast);
if $<separator>[0]<septype> eq '%%' {
$qast := QAST::Regex.new( :rxtype<concat>, $qast,
QAST::Regex.new( :rxtype<quant>, :min(0), :max(1), $<separator>[0].ast ));
}
}
$qast.backtrack('r') if $qast && !$qast.backtrack && %*RX<r>;
make $qast;
}

method separator($/) {
make $<quantified_atom>.ast;
}

method atom($/) {
make $<metachar>
Expand Down
10 changes: 9 additions & 1 deletion src/QRegex/P6Regex/Grammar.nqp
Expand Up @@ -61,9 +61,17 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
}

token quantified_atom {
<atom> [ <.ws> [ <quantifier> | <?before ':'> <backmod> <!alpha> ] ]?
<atom>
[
<.ws> [ <quantifier> | <?before ':'> <backmod> <!alpha> ]
[ <.ws> <separator> ]?
]?
}

token separator {
$<septype>=['%''%'?] <normspace>? <quantified_atom>
}

token atom {
# :dba('regex atom')
[
Expand Down

0 comments on commit 879321b

Please sign in to comment.