zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: _main_complete:343: bad pattern: a[
Date: Mon, 6 Dec 2010 10:46:05 +0000	[thread overview]
Message-ID: <20101206104605.368f920b@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <AANLkTinYNDGhEk1Xi892cB9SeWp+y5wwLsb_iLmQG0zg@mail.gmail.com>

On Mon, 6 Dec 2010 02:53:44 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> On 22 November 2009 19:22, Mikael Magnusson <mikachu@gmail.com> wrote:
> > % zsh -f
> > % autoload -U compinit; compinit
> > % $a[[<tab>
> > _main_complete:343: bad pattern: a[
> 
> There are lots of places in the code that say "bad pattern:", after
> adding identifiers to all of them, I found it's this one in glob.c
> 
>     if (!q || errflag) {	/* if parsing failed */
> 	restore_globstate(saved);
> 	if (unset(BADPATTERN)) {
> 	    if (!nountok)
> 		untokenize(ostr);
> 	    insertlinknode(list, node, ostr);
> 	    return;
> 	}
> 	errflag = 0;
>         /* $a[[<tab> */
> 	zerr("bad pattern: %s", ostr);
> 	return;
>     }
> 
> around line 1730. The real weird thing is that this is triggered by
> _lastcomp=( "${(@kv)compstate}" )
> in _main_complete. Trying to just echo $compstate or variations
> thereof fail in the same way. Now of course I'm curious why anything
> is trying to match a pattern when accessing a variable. Breaking at
> the print shows this backtrace, I realize I have no idea what any of
> these functions are for.

The pattern match is coming from the fact that this is an assignment of
an array, which does globbing.  The globbing should have no effect here
because there shouldn't be any patterns in the assignment.  One of the
values of compstate was therefore letting a token through.  It looks
like it was $compstate[parameter].  Any command line with compstate in
it would similarly look like a failed pattern match.

Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.101
diff -p -u -r1.101 compcore.c
--- Src/Zle/compcore.c	29 Jul 2010 11:08:28 -0000	1.101
+++ Src/Zle/compcore.c	6 Dec 2010 10:44:45 -0000
@@ -648,6 +648,17 @@ callcompfunc(char *s, char *fn)
         else
             compredirs = (char **) zshcalloc(sizeof(char *));
 
+	/*
+	 * We need to untokenize compparameter which is the
+	 * raw internals of a parameter subscript.
+	 *
+	 * The double memory duplication is a bit ugly: the additional
+	 * dupstring() is necessary because untokenize() might change
+	 * the string length and so later zsfree() would get the wrong
+	 * length of the string.
+	 */
+	compparameter = dupstring(compparameter);
+	untokenize(compparameter);
 	compparameter = ztrdup(compparameter);
 	compredirect = ztrdup(compredirect);
 	zsfree(compquote);

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


      reply	other threads:[~2010-12-06 10:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-22 18:22 Mikael Magnusson
2010-12-06  1:53 ` Mikael Magnusson
2010-12-06 10:46   ` 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=20101206104605.368f920b@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.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).