Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Problem with a substitution
- X-seq: zsh-users 23878
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Problem with a substitution
- Date: Sun, 17 Mar 2019 04:33:59 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=jleN050ygxsoLuZnTlaW3Lw/PfWKv2dDXwKH/xr/f5A=; b=tYl/MwoFQLO0uPlg123TW8yMNHP1UnEUuUB2BMUtMrP0OMm+T5hXucO/8+z/cJ9p5K eKMH0VFs9CY6iZhCP1xOr0OSa5IA21147N77f+JaoupTUD3LFuJyedikl/iok+cnNKBt 71h4Cn0+Dc1w+EcW9UuXkZr+UxHLOjUZc/xXltdTTldQOhGw3jkm7li5rnWSj6tySMDn +xMZ1FrvApfmQaa3M5PdG/pZyQJZYofyTkJcTOtKQaq60h9nlcryw/Pn5MnS2s2Ujhfs SErVg3XxttuivvBUPVqvmUTuEJS5iabEK9xAftA/8pSTjKsRetzL0EI16F1e+w+IT0P8 odOg==
- In-reply-to: <CAKc7PVDxXnkFaC9oSUCm-59tYpofA3HwiY09XewfBvGruGY8Eg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author