Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 'case' pattern matching bug with bracket expressions
On 5/14/15 10:42 AM, Peter Stephenson wrote:
> The handling of ']' at the start is mandated, if I've
> followed all the logic corretly --- POSIX 2007 Shell and Utilities
> 2.13.1 says:
>
> [
> If an open bracket introduces a bracket expression as in XBD RE
> Bracket Expression, except that the <exclamation-mark> character (
> '!' ) shall replace the <circumflex> character ( '^' ) in its role
> in a non-matching list in the regular expression notation, it shall
> introduce a pattern bracket expression. A bracket expression
> starting with an unquoted <circumflex> character produces
> unspecified results. Otherwise, '[' shall match the character
> itself.
>
> The languaqge is a little turgid, but I think it's saying "unless
> you have ^ or [ just go with the RE rules in [section 9.3.5]".
I think it means that improperly-formed pattern bracket expressions have
to be matched by a literal `[' followed by whatever the following
characters mean.
> I haven't read through the "case" doc so there may be some killer reason
> why that " | " has to be a case separator and not part of a
> square-bracketed expression. But that would seem to imply some form of
> hierarchical parsing in which those characters couldn't occur within a
> pattern.
It's the grammar. If you want `|' to be in a pattern you have to quote it.
Otherwise it's a metacharacter and a token delimiter (section 2.2).
The basic idea is that you tokenize case patterns as words and analyze them
as patterns after doing so.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@xxxxxxxx http://cnswww.cns.cwru.edu/~chet/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author