Skip to content

Commit

Permalink
Lookahead, positive and negative.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Oct 3, 2012
1 parent 94286df commit 2d70bfa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/QRegex/P5Regex/Actions.nqp
Expand Up @@ -178,7 +178,35 @@ class QRegex::P5Regex::Actions is HLL::Actions {
QAST::SVal.new( :value(~$<number> - 1) ) ) );
}
}

method p5assertion:sym<=>($/) {
if $<nibbler> {
make QAST::Regex.new(
:rxtype<subrule>, :subtype<zerowidth>, :node($/),
QAST::Node.new(
QAST::SVal.new( :value('before') ),
qbuildsub($<nibbler>.ast, :anon(1), :addself(1))
));
}
else {
make 0;
}
}

method p5assertion:sym<!>($/) {
if $<nibbler> {
make QAST::Regex.new(
:rxtype<subrule>, :subtype<zerowidth>, :negate(1), :node($/),
QAST::Node.new(
QAST::SVal.new( :value('before') ),
qbuildsub($<nibbler>.ast, :anon(1), :addself(1))
));
}
else {
make 0;
}
}

method p5mods($/) {
for nqp::split('', ~$<on>) {
%*RX{$_} := 1;
Expand Down
3 changes: 3 additions & 0 deletions src/QRegex/P5Regex/Grammar.nqp
Expand Up @@ -88,6 +88,9 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {

proto token p5assertion { <...> }

token p5assertion:sym<=> { <sym> [ <?before ')'> | <nibbler> ] }
token p5assertion:sym<!> { <sym> [ <?before ')'> | <nibbler> ] }

token p5mod { <[imox]>* }
token p5mods { <on=p5mod> [ '-' <off=p5mod> ]? }
token p5assertion:sym<mod> {
Expand Down

0 comments on commit 2d70bfa

Please sign in to comment.