Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[v6] Stop runaway backtracking in Cursor.lineof
  • Loading branch information
sorear committed Nov 16, 2010
1 parent 29ec560 commit 9912342
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions v6/tryfile
Expand Up @@ -22,13 +22,14 @@ augment class NAME {
}

augment class Regex {
sub first(\$x) { for $x -> $elt { return $elt }; Any }
method ACCEPTS($st) {
my $i = 0;
my $str = $st.Str;
my $mat;
my $C = Cursor.new($str);
while !$mat && ($i <= $str.chars) {
($mat,) = (self)($C.cursor($i++));
$mat = first((self)($C.cursor($i++)));
}
$mat ?? unitem($mat) !! Any;
}
Expand Down Expand Up @@ -295,8 +296,8 @@ my %terminator = (:dba('terminator') , :prec<a=>, :assoc<list>);
my $line = @*MEMOS[$p]<L>;
return $line if $line;
$line = 1; my $pos = 0;
self.orig ~~ / [ \n { @*MEMOS[$pos++]<L> = $line++ } ||
. { @*MEMOS[$pos++]<L> = $line } ]* /;
self.orig ~~ / :r [ \n { @*MEMOS[$pos++]<L> = $line++ } ||
. { @*MEMOS[$pos++]<L> = $line } ]* /;
@*MEMOS[$pos++]<L> = $line;
return @*MEMOS[$p]<L> // 0;
}
Expand Down

0 comments on commit 9912342

Please sign in to comment.