From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 4e876b53 for ; Sun, 17 Mar 2019 03:34:59 +0000 (UTC) Received: (qmail 20549 invoked by alias); 17 Mar 2019 03:34:45 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23878 Received: (qmail 28382 invoked by uid 1010); 17 Mar 2019 03:34:45 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f173.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25384. spamassassin: 3.4.2. Clear:RC:0(209.85.167.173):SA:0(-2.0/5.0):. Processed in 1.724629 secs); 17 Mar 2019 03:34:45 -0000 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.173 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=jleN050ygxsoLuZnTlaW3Lw/PfWKv2dDXwKH/xr/f5A=; b=n0voyjPEH7buIJbU1KF8ngConTrPIJ3INUVsDrW1l8o8Uk0VW1JFO4CB95DZty+KPZ nBar+aXyHKldeP0xvnifKVgTZ/YkM/TInGeT9HM1tN0HGJg0xi62Rhl0BEJ6FYeoEBuy 9QCZBrjX0uZB7nE0XBuohJUaP5qI/xmUQcvy//vqzpzScBPef/D05SgdmikhPvx96tH4 1/BuUGcK69+7MEXNYxz9XE9MgEjxERWKrIJTOFiGSX0yudvWOB0tXAY1egyVeiYeB24N EG4dWkHFqtoFZO7pYwY/OT+u738Yd2yEb7pTa4DYdSEONoAouSTMSijrkN9vK6SkNn+i bm3Q== X-Gm-Message-State: APjAAAUeeeb0P9UKQIzf6GPsVvM2kgUAIWYi8dDGf9kQ4kqMaZbfwVls ePPAWO4KwKqj7q2EAycCGRPKDkhebGAyJZAFRgrHbv1h X-Google-Smtp-Source: APXvYqzUiYy5vkJ3kbL5A0cEDGEajUXPwlp2R7uQHUKXAhlGh4p4MwGtFI4q/OItmTVjIgC0jUFb0sQeYFj6it620vQ= X-Received: by 2002:a54:4f85:: with SMTP id g5mr387901oiy.35.1552793650950; Sat, 16 Mar 2019 20:34:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sebastian Gniazdowski Date: Sun, 17 Mar 2019 04:33:59 +0100 Message-ID: Subject: Re: Problem with a substitution To: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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:]=3D]#(([a-zA-Z-]##)~(-q|--force|-f))#... I wonder why such effect? On Sun, 17 Mar 2019 at 03:55, Sebastian Gniazdowski 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:]=3D]#(([a-zA-Z-]#)~(-= -quiet|-q|--force|-f))#/${TARGET[${match[1]}]::=3D${match[1]}//${${match[2]= :+${match[2]}}:-1} > }}} > > Explanation: > > > ${(j::)${@[@]// > # Work on the command line arguments =E2=80=93 substitute sub-strings (i.= e. > the "//" substitution) > > (#b)(--quiet|-q|--force|-f) > # Enable $match array (the #b); match 4 different option cases > > [[:blank:]=3D]# > # Optional before-option's-value space and =3D > > (([a-zA-Z-]#)~(--quiet|-q|--force|-f))# > # Optional value =E2=80=93 a string from letters and dashes, but not any = of > the 4 option-names > > / > # Substitute to: > > ${TARGET[${match[1]}]::=3D${match[1]} > # option name, also assigning it to the TARGET hash (the ::=3D) > > //${${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:]=3D]#(([a= -zA-Z-]#)~(-q|--force|-f))#/${TARGET[${match[1]}]::=3D${match[1]}//${${matc= h[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 --=20 Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org