From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5192 invoked by alias); 27 Oct 2015 11:48:38 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36982 Received: (qmail 12368 invoked from network); 27 Oct 2015 11:48:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-64-562f62349e89 Date: Tue, 27 Oct 2015 11:37:59 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Issue with ${var#(*_)(#cN,M)} Message-id: <20151027113759.6b606836@pwslap01u.europe.root.pri> In-reply-to: <20151027111138.GB8170@chaz.gmail.com> References: <20151019093316.GA6957@chaz.gmail.com> <151019121728.ZM324@torch.brasslantern.com> <20151020190946.GA6560@chaz.gmail.com> <151020160422.ZM1778@torch.brasslantern.com> <20151027100034.45f487f0@pwslap01u.europe.root.pri> <20151027104633.2479414f@pwslap01u.europe.root.pri> <20151027110353.GA8170@chaz.gmail.com> <20151027111138.GB8170@chaz.gmail.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsVy+t/xK7omSfphBvePqFkcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujDmXzzEXTBGpeH55PmMD436BLkYODgkBE4kD25O7GDmBTDGJ C/fWs4HYQgJLGSUuH+LrYuQCsmcwSTxdto0VwtnGKHHm4GpmkCoWAVWJLa1zGUFsNgFDiamb ZoPZIgLiEmfXnmcBWSAsoCWx6nUlSJhXwF5i+b697CA2p4CxxN7VC6FmfmGSWPK4iwUkwS+g L3H17ycmiIvsJWZeOcMI0Swo8WPyPbAaZqCZm7c1sULY8hKb17xlhrhaXeLG3d3sExiFZiFp mYWkZRaSlgWMzKsYRVNLkwuKk9JzDfWKE3OLS/PS9ZLzczcxQkL2yw7GxcesDjEKcDAq8fAa VOiFCbEmlhVX5h5ilOBgVhLhvRijHybEm5JYWZValB9fVJqTWnyIUZqDRUmcd+6u9yFCAumJ JanZqakFqUUwWSYOTqkGRq1526pPJjFcaBDPzr0h+9sylb8knam8LnuW2mmLXXOWdN+8+uuM 4K7Fl9MeX1h2f9fhe8vOlvFHte5+2HaZs+qMkdRvm+D1r6t91rmuWapQomX2bJ/OK5byJZs5 NbPipnnV+K3KkLPmS/6kvL6Du8/5/kGROiOjJcKxe5yjn60SuhStYjC3QImlOCPRUIu5qDgR AOyfxFVVAgAA 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