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

Commit

Permalink
Add <?> (null) and <!> (fail) assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 14, 2009
1 parent 9ca78a9 commit a3bc5aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Regex/P6Regex/Actions.pm
Expand Up @@ -256,15 +256,25 @@ method backslash:sym<misc>($/) {


method assertion:sym<?>($/) {
my $past := $<assertion>.ast;
$past.subtype('zerowidth');
my $past;
if $<assertion> {
$past := $<assertion>.ast;
$past.subtype('zerowidth');
}
else { $past := 0; }
make $past;
}

method assertion:sym<!>($/) {
my $past := $<assertion>.ast;
$past.negate( !$past.negate );
$past.subtype('zerowidth');
my $past;
if $<assertion> {
$past := $<assertion>.ast;
$past.negate( !$past.negate );
$past.subtype('zerowidth');
}
else {
$past := PAST::Regex.new( :pasttype('anchor'), :subtype('fail') );
}
make $past;
}

Expand Down
2 changes: 1 addition & 1 deletion t/p6regex/rx_lookarounds
Expand Up @@ -37,7 +37,7 @@ x | y | <?> \t\n\r !"#$%&'()*+,-./:;<=>?@[\]^`_{|}0123456789ABCDEFGHIJabcdefghij

abc <!> def \t\n\r !"#$%&'()*+,-./:;<=>?@[\]^`_{|}0123456789ABCDEFGHIJabcdefghij n fail pattern <!>

a[b} \t\n\r !"#$%&'()*+,-./:;<=>?@[\]^`_{|}0123456789ABCDEFGHIJabcdefghij /rule error/ mismatched close
a[b} \t\n\r !"#$%&'()*+,-./:;<=>?@[\]^`_{|}0123456789ABCDEFGHIJabcdefghij /error/ mismatched close

c <before .d> abacad /mob: <c @ 3>/ one character and lookahead <before>
.* <before .d> abacad /mob: <abac @ 0>/ multiple characters and lookahead <before>
Expand Down

0 comments on commit a3bc5aa

Please sign in to comment.