zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Typeset with array
Date: Fri, 19 Jun 2015 12:39:30 +0100	[thread overview]
Message-ID: <20150619123930.2688d9e3@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150612094237.338f79d5@pwslap01u.europe.root.pri>

On Fri, 12 Jun 2015 09:42:37 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> > } > }     local cword words=()
> 
> It could, in principle, be very difficultly and time-consumingly
> improved.
> 
> We need in any case to keep the builtin interface to handle cases like
> 
>   local=local
>   $local -i i
> 
> which are valid --- the case
> 
>   $local array=(one two)
> 
> is not valid as there's no keyword to signal special parsing.

Building on the above, I've developed a Cunning Plan so that it's not
too disruptive and is a few days rather than weeks of spare time.

It works like this.

Reserved words are added for typeset synonyms that can handle arrays:
declare, local, readonly, typeset.  On second thoughts I added it to
export which supports "export -T"; it's a bit arbitrary if you can't
assign to the array component in that case, even though export isn't
generally useful for arrays.  For numeric builtins there's no point.

The reserved words trigger variant handling in par_simple(): WC_TYPESET
is very similar to WC_SIMPLE but there's an extra count and set of
assignments tacked on the end.

Here's where the Cunning Plan comes in: the spcial assignment behaviour
only kicks in where there's an actual assignment.  For consistency I did
it for scalars as well as arrays.  So if it comes across something like

  typeset -L2 name foo=bar array=(here there)

then the "-L2 name" is handled in the original way, but the
last two arguments are bundled up as assigments.  This means,
later on, the option parsing code needs no changes at all --
typeset options are simple and can't include arbitrary strings
with "=", so this doesn't confuse the parser.  To preserve
order, bare names after the first assignment are treated
as pseudo-assignments, specially marked as having no value
(which is different from an assignment with an empty value).

The execcmd code then handles WC_TYPESET much like WC_SIMPLE, but if
it's executing a builtin it extracts the assignments, sticks them in a
linked list, and performs prefork and globbing expansion.  I enhanced
struct asgment to do this: it's got an embedded LinkNode, which we do a
lot with HashNode but not elsewhere with LinkNode, however I think it
works OK.

The bin_typeset handler has a different interface from the other
builtins, accepting this extra linked list.  The flag BINF_ASSIGN in the
table indicates this (obviously it's needed for all instances of
bin_typeset, not just those that handle the extra assignments --- which
just get a null list).

There are other tweaks to bin_typeset() and typeset_single() to handle
the new cases.  This is already hairy code, so there could easily be
oddities here, but they don't generally affect things that already work,
so far as I can see.  The key changes are that getasg() is enhanced to
pull values off argv and the new list; when creating a parameter with an
array assignment it's turned into PM_ARRAY; and setsparam() calls now
have parallel setaparam() calls for the other case.

Currently the reserved words are enabled since in theory the disruption
to existing working code should be minimal.  If we find a good reason we
can disable them by default in native mode.

I've got as far as a successful

% typeset array=(one two buckle my shoe)
% print -l $array
one
two
buckle
my
shoe

but there's a lot more debugging and testing to do.  Also, execcmd()
needs some work --- currently, the reserved word doesn't actually force
you to use a builtin of the same name, we just rely on execcmd() finding
the builtin in the hash table.  If that was disabled but there was an
external command of the same name it would execute that, missing the
special assigment commands on the end.  This probably isn't the right
thing to do.

This is on a branch typeset-array, which I'll push so you can have a
look.  When it's stable I'll rebase, squash and merge -ff-only onto the
end of master.

pws


       reply	other threads:[~2015-06-19 11:50 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5578996E.3080700@thequod.de>
     [not found] ` <150610191427.ZM30841@torch.brasslantern.com>
     [not found]   ` <5579C247.1060800@thequod.de>
     [not found]     ` <150611183639.ZM32247@torch.brasslantern.com>
     [not found]       ` <20150612094237.338f79d5@pwslap01u.europe.root.pri>
2015-06-19 11:39         ` Peter Stephenson [this message]
2015-06-19 14:06           ` Peter Stephenson
2015-06-19 18:54             ` Bart Schaefer
2015-06-19 20:16               ` Peter Stephenson
2015-06-19 21:11               ` Eric Cook
2015-06-19 16:09           ` Bart Schaefer
2015-06-19 20:32             ` Peter Stephenson
2015-06-20  3:50               ` Bart Schaefer
2015-06-20 17:05                 ` Peter Stephenson
2015-06-19 17:36           ` Oliver Kiddle
2015-06-19 18:40             ` Bart Schaefer
2015-06-25  9:29             ` Peter Stephenson
2015-06-25 15:16               ` Bart Schaefer
2015-06-25 15:39                 ` Peter Stephenson
2015-06-25 16:08                   ` Bart Schaefer
2015-06-25 16:34                     ` Peter Stephenson
2015-06-26 13:51               ` PATCH: array slice Peter Stephenson
2015-06-26 23:07                 ` Bart Schaefer
2015-06-27 19:42                   ` Peter Stephenson
2015-06-27 20:09                     ` Bart Schaefer
2015-06-26 16:46               ` PATCH: typeset completion Peter Stephenson
2015-06-26 19:14               ` Typeset with array Oliver Kiddle
2015-06-27 16:33                 ` Peter Stephenson
2015-06-21 20:05           ` Peter Stephenson
2015-06-21 20:38             ` Peter Stephenson
2015-06-23 16:47               ` Peter Stephenson
2015-06-23 17:52                 ` Mikael Magnusson
2015-06-23 20:17                   ` Bart Schaefer
2015-06-23 20:21                     ` Peter Stephenson
2015-06-23 20:24                     ` Mikael Magnusson
2015-06-24  1:35                       ` typeset -p with assoc array (was Re: Typeset with array) Bart Schaefer
2015-06-24  6:03                         ` Bart Schaefer
2015-06-23 20:25                 ` Typeset with array Bart Schaefer
2015-06-24  9:14                   ` Peter Stephenson
2015-06-24  9:29                     ` Peter Stephenson
2015-06-24 10:35                       ` Roman Neuhauser
2015-06-24 13:00                       ` Mikael Magnusson
2015-06-24 13:20                         ` Peter Stephenson
2015-06-24 15:03                     ` Bart Schaefer

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=20150619123930.2688d9e3@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).