zsh-workers
 help / color / mirror / code / Atom feed
* (#cN,M) error, %? doesn't glob
@ 2011-06-24  2:00 Mikael Magnusson
  2011-06-24  4:12 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2011-06-24  2:00 UTC (permalink / raw)
  To: zsh workers

Someone asked on irc if there was a way to limit **/foo to 2 levels,
and I explained how **/ is short for (*/)# so he should be able to use
(*/)(#c,2), but that produces a bad pattern error. The manual says
that "The flag (#cN,M) can be used anywhere that the # or ## operators
can be used".

(*/)# is special-cased together with **/ in parsecomplist(), so it is
nontrivial to make it parse (#c) stuff, so here's an update for the
documentation to add an exception. Looking further, not just the
parsing but the whole scanner knows about this construct and hardcodes
0/1 or more dirs behaviour, so it would be a lot of work to change.

--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1992,7 +1992,8 @@ point on.
 )
 item(tt(c)var(N)tt(,)var(M))(
 The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
-that the tt(#) or tt(##) operators can be used; it cannot be combined
+that the tt(#) or tt(##) operators can be used except in the expressions
+`tt((*/)#)' and `tt((*/)##)'; it cannot be combined
 with other globbing flags and a bad pattern error occurs if it is
 misplaced.  It is equivalent to the form tt({)var(N)tt(,)var(M)tt(}) in
 regular expressions.  The previous character or group is required to


While looking at Src/glob.c I also noticed that ? is ignored for
globbing if it is preceded by a % at the start of a string, is that
documented anywhere? bash doesn't have this behaviour, and emulate sh
obviously doesn't help.
    /* If % is immediately followed by ?, then that ? is     *
     * not treated as a wildcard.  This is so you don't have *
     * to escape job references such as %?foo.               */
    if (str[0] == '%' && str[1] == Quest)
	str[1] = '?';
I would argue that if someone is too lazy to escape their job
references they should just setopt nonomatch. I can imagine files like
that existing if you downloaded some nonlatin filenames via http and
they were saved percent-escaped, then you might want to find such
files with %??%* or something, maybe? I know that at least I would be
very confused if zsh then told me "no matches found", viz,
% touch %ab%de
% echo %??%*
zsh: no matches found: %??%*
% echo (#)%??%*
%ab%de

I sort of feel like an explicit option for this would be a bit awkward.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (#cN,M) error, %? doesn't glob
  2011-06-24  2:00 (#cN,M) error, %? doesn't glob Mikael Magnusson
@ 2011-06-24  4:12 ` Bart Schaefer
  2011-08-14  7:44   ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2011-06-24  4:12 UTC (permalink / raw)
  To: zsh workers

On Jun 24,  4:00am, Mikael Magnusson wrote:
}
}  The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
} +that the tt(#) or tt(##) operators can be used except in the expressions
} +`tt((*/)#)' and `tt((*/)##)'

That's not quite right.  [[ bar/foo == (*/)(#c1,2)foo ]] does not produce
a bad pattern error.  It's only in glob context where "/" has special
significance that (*/)# is also a special case.

} While looking at Src/glob.c I also noticed that ? is ignored for
} globbing if it is preceded by a % at the start of a string, is that
} documented anywhere?

Etc/BUGS -- second to last entry.

} I sort of feel like an explicit option for this would be a bit awkward.

See one proposed fix in Etc/BUGS ...

I believe this behavior is actually "inherited" from csh -- one original
design goal of zsh was to import as much as possible of csh's interactive
behavior into the Bourne shell's syntax structure.

Tcsh seems to have solved it by making builtins that manipulate jobs into
special keywords that alter the parse of what comes after, much in the
way that ksh applies assignment context to arguments that follow the
typeset and local builtins:

$ echo %?foo
echo: No match.
$ fg %?foo
fg: No job matches pattern.



-- 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (#cN,M) error, %? doesn't glob
  2011-06-24  4:12 ` Bart Schaefer
@ 2011-08-14  7:44   ` Mikael Magnusson
  2011-08-14 22:56     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2011-08-14  7:44 UTC (permalink / raw)
  To: zsh workers

On 24 June 2011 06:12, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jun 24,  4:00am, Mikael Magnusson wrote:
> }
> }  The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
> } +that the tt(#) or tt(##) operators can be used except in the expressions
> } +`tt((*/)#)' and `tt((*/)##)'
>
> That's not quite right.  [[ bar/foo == (*/)(#c1,2)foo ]] does not produce
> a bad pattern error.  It's only in glob context where "/" has special
> significance that (*/)# is also a special case.

How's this?

The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
that the tt(#) or tt(##) operators can be used except for in the expressions
`tt((*/)#)' and `tt((*/)##)' while globbing, which are handled specially;
it cannot be combined with other globbing flags and a bad pattern error
occurs if it is misplaced.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (#cN,M) error, %? doesn't glob
  2011-08-14  7:44   ` Mikael Magnusson
@ 2011-08-14 22:56     ` Bart Schaefer
  2011-08-14 23:21       ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2011-08-14 22:56 UTC (permalink / raw)
  To: zsh workers

On Aug 14,  9:44am, Mikael Magnusson wrote:
}
} The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
} that the tt(#) or tt(##) operators can be used except for in the expressions
} `tt((*/)#)' and `tt((*/)##)' while globbing, which are handled specially;
} it cannot be combined with other globbing flags and a bad pattern error
} occurs if it is misplaced.

Make it

  except in the expressions `tt((*/)#)' and `tt((*/)##)' in filename
  generation, where `tt(/)' has special meaning;

and I'm all for it.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (#cN,M) error, %? doesn't glob
  2011-08-14 22:56     ` Bart Schaefer
@ 2011-08-14 23:21       ` Mikael Magnusson
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2011-08-14 23:21 UTC (permalink / raw)
  To: zsh workers

On 15 August 2011 00:56, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Aug 14,  9:44am, Mikael Magnusson wrote:
> }
> } The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
> } that the tt(#) or tt(##) operators can be used except for in the expressions
> } `tt((*/)#)' and `tt((*/)##)' while globbing, which are handled specially;
> } it cannot be combined with other globbing flags and a bad pattern error
> } occurs if it is misplaced.
>
> Make it
>
>  except in the expressions `tt((*/)#)' and `tt((*/)##)' in filename
>  generation, where `tt(/)' has special meaning;
>
> and I'm all for it.

Thanks, that sounds much better. And I feel like "filename generation"
is more specific than "when globbing" too, it should be valid in y in
x~y for example, but I didn't test this :).

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-08-14 23:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-24  2:00 (#cN,M) error, %? doesn't glob Mikael Magnusson
2011-06-24  4:12 ` Bart Schaefer
2011-08-14  7:44   ` Mikael Magnusson
2011-08-14 22:56     ` Bart Schaefer
2011-08-14 23:21       ` Mikael Magnusson

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).