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

Re: _subscript quotes too much



On Wed, 09 Apr 2008 09:49:04 +0100
Peter Stephenson <pws@xxxxxxx> wrote:
> > >  % typeset -A foo
> > >  % foo[*.txt]=blue
> > >  % echo $foo[\*.txt]
> > >
> > >  % echo $foo[*.txt]
> > >  blue
>
> I've a vague feeling that not handling \* the same as * is a bug, but
> quoting in subscripts is a horrible can of worms.  I would expect
> backslash-quoting, at least, to be uniformly applied.

Hmm... it isn't, and this appears to be deliberate at at least two points
in the code: lex.c:dquote_parse() (where we carefully choose when to make
backslashes active) and params.c:getarg() (where we put most of the active
backslashes back to real backslashes anyway).  So we're actually going to
some lengths to make sure backslashes are *not* handled as quote characters
in subscripts but are retained.  This is documented in Subscript Parsing in
the zshparam manual, in fact, where there's a long essay about why it's so
difficult.  The paradigm is double quotes, where only some backslashed
characters are treated specially:

% print -r "\*"
\*

The usual workaround is to use a parameter.

As far as _subscript is concerned, it would have to be taught the rules for
which characters can be backslashed, this applied with ${...//.../...}, and
then the -Q flag passed to compadd.  This shouldn't be too hard.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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