Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created February 24, 2013 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/5023634 to your computer and use it in GitHub Desktop.
Save FROGGS/5023634 to your computer and use it in GitHub Desktop.
patch for returning Nil for failed matches
diff --git a/src/core/Cursor.pm b/src/core/Cursor.pm
index 2654bfe..d6f81c8 100644
--- a/src/core/Cursor.pm
+++ b/src/core/Cursor.pm
@@ -41,8 +41,11 @@ my class Cursor does NQPCursorRole {
method MATCH_SAVE() {
my $match := self.MATCH();
- $last_match := $match if $match;
- $match;
+ if $match {
+ $last_match := $match;
+ return $match
+ }
+ Nil
}
# INTERPOLATE will iterate over the string $tgt beginning at position 0.
@@ -79,7 +82,7 @@ my class Cursor does NQPCursorRole {
$match := nqp::substr($tgt, $pos, $eos - $pos) ~~ $topic;
# In order to return the correct result we need to match from the
# current position only.
- next if $match.from;
+ next if !$match || $match.from;
$match := ~$match;
$len := nqp::chars( $match );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment