From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIM_ADSP_ALL,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20022 invoked from network); 12 Nov 2021 19:59:43 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Nov 2021 19:59:43 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1636747183; b=dIss/yXhdCuxtgPKlIGdBJIeirIm9v0+OUpmIuNtKv7bTzDSzTrvpvxxE808C3qkQ+wmq00qz7 XA95i6uD2P2AtnaRvfu0WkfwX/7ajjabVKmbC2awKpEbq80DTEvS98qNcBOAXxIG+wAf+sdqpy Vc5DZonZd9x0SyYCZ/feyaiBw9DXioiMqxl6QIpUjD6hAMpuu0ZP0GV5Bo5RxpYadXEVWxGugh 1NR5K4RffInzy64cPDHDpJvnMeplRrPTGQbb7MVjKnlVixuM2cjsNEBQI9mZYbDZ4LxQe7CFTk 3HdqzHO0Y/znR0tRr39O2iBsIUSkMx5q9zmDyb+LrZybaA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mx.cs.msu.ru) smtp.remote-ip=188.44.42.42; dkim=pass header.d=cs.msu.ru header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=cs.msu.ru; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1636747183; bh=CWMZ8bsErTraMYjIwpJap5xPzfVhK9FPCzi+MO2J1qk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:In-Reply-To:Content-Type:MIME-Version:References: Message-ID:To:From:Date:DKIM-Signature:DKIM-Signature; b=D7LJbuAtlNY91xCWLuBR/p7jEZ8zbMza5zt1sdL0iZKv2SXl+C/o1BNs0k9u4Kaq/39uzqqMhG beHx/Mi8IK1OwLNRcIMNRt9/tMzq6WdrdpG48OQ0Y7s4jOLW5e9iKZJ0FaiSv9ySAe9qD5jdem CuLA+nf/ytYcRjyT8qbJGi3y24EAqzbvG/nvsGJsbn7X6C70EMApEs/ktwAI+iXI0j8WGjDbO/ F0lVOUmhkrOMgfo1V9zqhApQNrAOBVi1PYdEd2NYe1Q75zPe37aCCbKx68rzcY7wWWqjfuj688 iuDPNUcG3vKXIb4HRJu1O62vsq8RcMXAayWY32Xxbnpc6Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Subject:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:To:From:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=EZdN1bW02tWKnoDvrLCZhrdztrXqpb+6POIZcSlfdQE=; b=eZzlQ3N8wTGoBEA1fCiMi2ovx7 buomfQ7HPQXChqWwJwu4FQ+GLUepZ5lNFpIAU0gV/p8IZFqisDukEQpzb7I8c+4yDYdGy3Xlu5ygz 4TNlim7ntXxKCFa9Mu3zUhdfNHaWMbwg93whrs94CxtqUt5dVgNyZH9nQs7GF+4O/NBsrUIe8RhHs FAN5ibEUBQSmMUhQSXv2T+SvplWg+EvBjC20ubm5E9bKAwqqKqX1d8a9WQW730VHMV0FFK18zvsNJ ETHUAXMsP2SngP1aOyxyGNUjpZjjhQlrgP/sB9QBo+gPkMlF4d8GCERv8x/OOelgjteFSIqiCodnF phZP9yxQ==; Received: from authenticated user by zero.zsh.org with local id 1mlci6-000Kp9-Vn; Fri, 12 Nov 2021 19:59:42 +0000 Authentication-Results: zsh.org; iprev=pass (mx.cs.msu.ru) smtp.remote-ip=188.44.42.42; dkim=pass header.d=cs.msu.ru header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=cs.msu.ru; arc=none Received: from mx.cs.msu.ru ([188.44.42.42]:47437 helo=mail.cs.msu.ru) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mlchQ-000KVE-8S; Fri, 12 Nov 2021 19:59:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:In-Reply-To:Content-Type:MIME-Version:References:Message-ID :To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=EZdN1bW02tWKnoDvrLCZhrdztrXqpb+6POIZcSlfdQE=; b=hTmpVC3GuUgJ/y4DZU0wviDjDg t2eYO+fAmPrRZkudACF7f7qLDOwEcyiuSEybXNskh3XT1o+1rjvQ1CjrvJvqQLkHYa6N3Kec+vCtl jtc9pdod6RVeaOGes8gMR5iU1nrkNNv7SJjc5AfzTObjHKeZg8uhK8ZA4KUHFszaoTuwwFk1SbSOp qTLCIhY3nLLmojxSt2T908ms9SGDq4eyoHuBu1JVBsTCmFQkP6tfygJc0BFV2/c6c0NOHtuUgwjMo +lklRyelH4oCFMnZwmIceTOKu9d9spFYpv52/8CP9RaH4F9zdM4pGlq+1yWdzd0IuBrIsi2Duv2fk Xe8NPpWQ==; Received: from [37.204.119.143] (port=57246 helo=cello) by mail.cs.msu.ru with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2 (FreeBSD)) (envelope-from ) id 1mlchN-000A4S-TW for zsh-workers@zsh.org; Fri, 12 Nov 2021 22:58:59 +0300 Date: Fri, 12 Nov 2021 22:58:56 +0300 From: Arseny Maslennikov To: zsh-workers@zsh.org Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RqS0Fbf/Urky9XLq" Content-Disposition: inline In-Reply-To: OpenPGP: url=http://grep.cs.msu.ru/~ar/pgp-key.asc X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: Re: Q: _alternative's `(( w1:d1 w2:d2 ))' form X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: No (on mail.cs.msu.ru); Unknown failure X-Seq: 49573 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --RqS0Fbf/Urky9XLq Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 12, 2021 at 10:32:56PM +0300, Arseny Maslennikov wrote: > Hi! >=20 > The doc page for _alternative (citing `info zsh`, menu item `Completion > Functions') states: > _alternative [ -O NAME ] [ -C NAME ] SPEC ... > <...> > The tags to use and the action to perform if a tag is requested are > described using the SPECs which are of the form: > 'TAG:DESCR:ACTION'. The TAGs are offered using _tags and if the > tag is requested, the ACTION is executed with the given description > DESCR. The ACTIONs are those accepted by the _arguments function > (described below), excluding the '->STATE' and '=3D...' forms. > <...> >=20 > Later on, the text for _arguments advises to escape the separating > colons between the match candidate and its description in a (( )) > action spec, due to more complex spec parsing and further optional > fields. A thorough reader of the docs might think the same is > required by _alternative as well. >=20 > I've been looking at the implementation of _alternative lately; the > function splits its specs into exactly 3 fields, delimited by `:'. The > following seems to be true: >=20 > * the first field is delimited by the first colon; > * the second field spans from after the first field's delimiter to the > nearest colon; > * the rest of the spec is interpreted as the action field, unlike > the specs for _arguments. >=20 On a related note: this looks so obvious with hindsight but I've found that the following way to avoid escaping the `:' works for _arguments too: function _ooo { local __ndescs=3D( '0:0' '1:1' '2:2' '3:3' '4:4' '5:5' '6:6' '7:7' '8:8' '9:9' 'A:10' 'B:11' 'C:12' 'D:13' 'E:14' 'F:15' ) _arguments '1:letter:(a b c y z)' '2:digit:(( "${(@)__ndescs}" ))' } The expansion of `__ndescs' happens during the action eval, and the expression does not contain any colons. This approach is surprisingly quite unpopular, especially in third-party completions =E2=80=94 instead, the authors prefer to use a function as the action, which then calls _describe by itself (here goes another while tags; do while _next_label; do done; done loop) and does not introduce new tags. --RqS0Fbf/Urky9XLq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE56JD3UKTLEu/ddrm9dQjyAYL01AFAmGOx3sACgkQ9dQjyAYL 01AJyA/+Np48YLhhgcYdWaElzjrKyH7vGpjos2ntBzLhMT1GVbHNogKUQ8pPsSHF Fb8VOwWP0KAlz67nqnksKb9g6vZ9wS7t4F1M9GoJW945W3VHRxi7KVsr/i2PEWC9 tC4LNRaJhT7eSWnrUFotgunaB5L2pAT/zmrDEMGIbiz89gcRUu5fjD4puZYMH62G T74uL2IkXqqiMGyL9gHfUNq8Xy9eE2UqFuVsG+haPCX8v/CXyDCtxzDYM4oDdK7f n0+z1+c5W9PqYdNtZ2dYRpOJN5kZIT6+SqNF+p1CNjrzjnmNoBv9HmS7S7fUOxIh OBmlI2UilDqNUN8VwPEaJuaY2rmNGOjWx1BmqOndfVYHYIW1K1YFl/TFKuye9BD8 ZQXBDu7X2wmGwbHSBzlofYCbwO6oeZMn7AFZTMh4c41+spLfTr9IVkHebvnaxXXc 0MvJcdNqjecrmQk43wXj5Ez1Hwa1CqwX5XEuyI1uOxetWOiZ9p0z3GzRr+RumUle pMwfwvicJAaIzgbVgs/LmrL/PwUzuGTNl77PaLSs+2jvCUvgPQjYgoM2gbeaMztu sHpTOiVn75PPzIj5j0T4TBBGxyS9ZWhf9EMF1fCmI6QKMCvDrRWyndCrVjSD5eLr /4CIkYhgw+y6UcU7o9EjcXRS1JpqN04yQw2Us7ZThkBnfc0yytE= =b0Xo -----END PGP SIGNATURE----- --RqS0Fbf/Urky9XLq--