Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug? RE: Un-patch: new pattern matching code



Andrej Borsenkow wrote:

> > Anyone who knows any computer science will probably notice that, while it's
> > pretty much a finite state machine, some states are more finite than
> > others.  In particularly, backtracking on excluded matches, where in
> > (foo~bar)rod the `bar' only has to match the `foo' and the `rod' is
> > irrelevant, need some extra state recording, and I have retained the old
> > trick that eliminates infinite loops and prevents exponential behaviour
> > when failing to match against things like `(f#o#)#' (the version of perl
> > here goes into an infinite loop when given `(f*o*)*', so it isn't trivial).
> > This has meant leaving holes for pointers in the compiled expression, which
> > ought to work (I've tried to make sure everything is aligned to pointer
> > size anyway) but is probably the most dubious part of the proceedings.
> > 
> 
> bor@itsrm2:~%> foo=ab12xy
> bor@itsrm2:~%> print ${foo/[[:digit:]]#}
> abxy
> bor@itsrm2:~%> print ${(S)foo/[[:digit:]]#}
> ab12xy
> bor@itsrm2:~%> print ${foo//[[:digit:]]#}  
> abxy
> bor@itsrm2:~%> print ${(S)foo//[[:digit:]]#}
> here zsh hangs completely.

It was repeatedly matching the empty string, of course. This makes
that be handled as a special case, stepping one character forward even 
if zero characters were matched.
Maybe Peter will have to decide if this is the right thing to do here.

Bye
 Sven

P.S.: At least simple things like ${a#*/}, ${a%/*}, ${a##*/}, and
      ${a%%/*} seem to be circa three times slower than before for me.

--- os/glob.c	Mon Aug  9 10:40:41 1999
+++ Src/glob.c	Mon Aug  9 10:33:49 1999
@@ -1971,8 +1971,11 @@
 				*ptr = sav;
 			    }
 			}
-			if (!--n || (n <= 0 && (fl & SUB_GLOBAL)))
+			if (!--n || (n <= 0 && (fl & SUB_GLOBAL))) {
 			    *sp = get_match_ret(*sp, t-s, mpos-s, fl, replstr);
+			    if (mpos == start)
+				mpos++;
+			}
 			if (!(fl & SUB_GLOBAL)) {
 			    if (n) {
 				/*

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author