zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Issue with ${var#(*_)(#cN,M)}
Date: Tue, 27 Oct 2015 11:37:59 +0000	[thread overview]
Message-ID: <20151027113759.6b606836@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20151027111138.GB8170@chaz.gmail.com>

Sigh.  Can't see the wood for the trees.  It is a backtracking problem,
but it's a simple bug with restoring the state when backtracking, not a
logical error in the matching machine.

I'll take out the weasel words again, shall I?

pws

diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 49a0f0d..5ea8610 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -2192,16 +2192,6 @@ inclusive.  The form tt(LPAR()#c)var(N)tt(RPAR()) requires exactly tt(N)
 matches; tt(LPAR()#c,)var(M)tt(RPAR()) is equivalent to specifying var(N)
 as 0; tt(LPAR()#c)var(N)tt(,RPAR()) specifies that there is no maximum
 limit on the number of matches.
-
-Note that if the previous group of characters contains wildcards,
-results can be unpredictable to the point of being logically incorrect.
-It is recommended that the pattern be trimmed to match the minimum
-possible.  For example, to match a string of the form `tt(1_2_3_)', use
-a pattern of the form `tt(LPAR()[[:digit:]]##_+RPAR()LPAR()#c3+RPAR())', not
-`tt(LPAR()*_+RPAR()LPAR()#c3+RPAR())'.  This arises from the
-complicated interaction between attempts to match a number of
-repetitions of the whole pattern and attempts to match the wildcard
-`tt(*)'.
 )
 vindex(MATCH)
 vindex(MBEGIN)
diff --git a/Src/pattern.c b/Src/pattern.c
index 8b07cca..9e8a80a 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -3376,6 +3376,7 @@ patmatch(Upat prog)
 		    scan[P_CT_CURRENT].l = cur + 1;
 		    if (patmatch(scan + P_CT_OPERAND))
 			return 1;
+		    scan[P_CT_CURRENT].l = cur;
 		    patinput = patinput_thistime;
 		}
 		if (cur < min)
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index 3e2095a..f944a4f 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -574,3 +574,11 @@
 0:Optimisation to squeeze multiple *'s used as ordinary glob wildcards.
 >glob.tmp/ra=1.0_et=3.5
 >glob.tmp/ra=1.0_et=3.5
+
+  [[ 1_2_ = (*_)(#c1) ]] && print 1 OK  # because * matches 1_2
+  [[ 1_2_ = (*_)(#c2) ]] && print 2 OK
+  [[ 1_2_ = (*_)(#c3) ]] || print 3 OK
+0:Some more complicated backtracking with match counts.
+>1 OK
+>2 OK
+>3 OK
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index f1cc23e..cb7079c 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1735,3 +1735,12 @@
 0:History modifier works the same for scalar and array substitution
 >ddd bdb cdc
 >ddd bdb cdc
+
+ a=1_2_3_4_5_6
+ print ${a#(*_)(#c2)}
+ print ${a#(*_)(#c5)}
+ print ${a#(*_)(#c7)}
+0:Complicated backtracking with match counts
+>3_4_5_6
+>6
+>1_2_3_4_5_6


      reply	other threads:[~2015-10-27 11:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19  9:33 Stephane Chazelas
2015-10-19 19:17 ` Bart Schaefer
2015-10-20 19:09   ` Stephane Chazelas
2015-10-20 23:04     ` Bart Schaefer
2015-10-27 10:00       ` Peter Stephenson
2015-10-27 10:46         ` Peter Stephenson
2015-10-27 11:03           ` Stephane Chazelas
2015-10-27 11:11             ` Peter Stephenson
2015-10-27 11:11             ` Stephane Chazelas
2015-10-27 11:37               ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151027113759.6b606836@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).