zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Problem with a substitution
Date: Sun, 17 Mar 2019 04:33:59 +0100	[thread overview]
Message-ID: <CAKc7PVBWvUf44d=HFwuErOHi+chZZ8Vq1qBHs8edJr8EfPhJZg@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVDxXnkFaC9oSUCm-59tYpofA3HwiY09XewfBvGruGY8Eg@mail.gmail.com>

It turned out that it was `#'-repeat-0-or-more the cause, changing it
to `##'-repeat-1-or-more solved the problem. It's the [a-zA-Z-]## in
the part below:

...[[:blank:]=]#(([a-zA-Z-]##)~(-q|--force|-f))#...

I wonder why such effect?

On Sun, 17 Mar 2019 at 03:55, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hello,
> I think that the parsing of command line can be performed by 1-2
> substitutions. Below is the one that I'm currently working on:
>
> ${(j::)${@[@]//(#b)(--quiet|-q|--force|-f)[[:blank:]=]#(([a-zA-Z-]#)~(--quiet|-q|--force|-f))#/${TARGET[${match[1]}]::=${match[1]}//${${match[2]:+${match[2]}}:-1}
> }}}
>
> Explanation:
>
>
> ${(j::)${@[@]//
> # Work on the command line arguments – substitute sub-strings (i.e.
> the "//" substitution)
>
> (#b)(--quiet|-q|--force|-f)
> # Enable $match array (the #b); match 4 different option cases
>
> [[:blank:]=]#
> # Optional before-option's-value space and =
>
> (([a-zA-Z-]#)~(--quiet|-q|--force|-f))#
> # Optional value – a string from letters and dashes, but not any of
> the 4 option-names
>
> /
> # Substitute to:
>
> ${TARGET[${match[1]}]::=${match[1]}
> # option name, also assigning it to the TARGET hash (the ::=)
>
> //${${match[2]:+${match[2]}}:-1} }}}
> # After-//, also assign optional option's value (using "1" if there's no value)
>
> So, for the following input:
> set -- --quiet -fa -q
> local -A TARGET
>
> the output of:
> print -r -- ${(j::)${@[@]//(#b)(--quiet|-q|--force|-f)[[:blank:]=]#(([a-zA-Z-]#)~(-q|--force|-f))#/${TARGET[${match[1]}]::=${match[1]}//${${match[2]:+${match[2]}}:-1}
> }}}
>
> is:
> --quiet//1 -f//1 -q//1
>
> and for:
> print -rl -- ${(kv)TARGET}
>
> it is (keys and values alternating):
> -q
> -q//1
> --quiet
> --quiet//1
> -f
> -f//1
>
> I.e.: there's no "-f//a" string in it. Why?
>
> --
> Sebastian Gniazdowski
> News: https://twitter.com/ZdharmaI
> IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> Blog: http://zdharma.org



-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

      reply	other threads:[~2019-03-17  3:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-17  2:55 Sebastian Gniazdowski
2019-03-17  3:33 ` Sebastian Gniazdowski [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='CAKc7PVBWvUf44d=HFwuErOHi+chZZ8Vq1qBHs8edJr8EfPhJZg@mail.gmail.com' \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@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).