From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2430 invoked by alias); 1 Jun 2018 10:56:37 -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: 23418 Received: (qmail 26000 invoked by uid 1010); 1 Jun 2018 10:56:37 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi0-f54.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.218.54):SA:0(-1.9/5.0):. Processed in 1.17705 secs); 01 Jun 2018 10:56:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7lkO8FhAKX4vFBBrnDglCBJamdPokOElaBDGPmvIxPU=; b=M13E4rEP2DOwj0jscCgR6IOmGwJnIgHx+BsoGZYsrUd5V6YWC2gsnYovUFrgrNhO5p zMT1JzfXGeQOw29Rj1iGQRWeAk8OdlQeuefC61eaj7or69NrcfXB9X+eUuWMrVTrpwDC iUM7Ro2Hzu6udSPjl6n60nX1erfIWgcwLwU0h1MFyykpDeWyyvfN5d0fRzc6UQRxYXeM mZzx1PuIqVd2Y43U0wE2YqQYhoaNiS3yELVb94pFpIzMiGdgHGs5UZEPlLRL8Bj0r9N2 gPQhXwoXz7EErv2aSNfesRE1EhkKL5ToylOzUXF5VE8pukFAut2ch5vR0PS73Li4eXlK R/mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7lkO8FhAKX4vFBBrnDglCBJamdPokOElaBDGPmvIxPU=; b=BukuMhxP08nmKJNWGBSMr/YdqSyqfohqSPzW6pxUxq9p+gkXuVhCkJTzFRpxQmjxNc AJRkyfieLupATmWaWIV39l9FDdkl/fT6bIW23o3aDkXfJNtpW5JzRrzQIZYWSOSWW02d rrC1Y8utv7s84WMo+aeL+D4OUZkqdknjuYoShOIfzXcpx7p+XD9epjIGO+pj/NmBeXSy B3K+tBYdj06z9MgxIs04Inj4jW1vQ85ZOYNy69A6lu4SVcvxrsqmfGwyEPuNr68nSnrQ qMdH0TtOtlQGVvGqwkB4dMzTZFfa5CqaATZ18hvpLD+TPcP9STANo8/2pPUtiPmAu4Ch 14Xw== X-Gm-Message-State: APt69E1s8tfhhPNNowlVvMeXzZ6aPEkAr+qpNDjJB+s2QGYbj0CpmbwK SwoY1ZAW631mjX1G2+KmIYftmscOQFndzXyuynI= X-Google-Smtp-Source: ADUXVKJ/k4QMht3JxxsMLGpxhNw0JQXk8gzQODt953aZVShvR/r2EDZdB+8atLkbFZsfJsegBt+KsIUgT3mzi/oDjyM= X-Received: by 2002:aca:bc84:: with SMTP id m126-v6mr6181299oif.169.1527850593589; Fri, 01 Jun 2018 03:56:33 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180601095018eucas1p1662451fd258f46cdfdee319db48458a8~0AGeNx_UX2206222062eucas1p1m@eucas1p1.samsung.com> References: <20180601095018eucas1p1662451fd258f46cdfdee319db48458a8~0AGeNx_UX2206222062eucas1p1m@eucas1p1.samsung.com> From: Sebastian Gniazdowski Date: Fri, 1 Jun 2018 12:56:13 +0200 Message-ID: Subject: Re: How to best match $( ... ) in a string To: Peter Stephenson Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" On 1 June 2018 at 11:50, Peter Stephenson wrote: > On Fri, 1 Jun 2018 10:44:58 +0200 > Sebastian Gniazdowski wrote: >> the problem is possible quoting, e.g. $( echo \) ). Has anyone a >> pattern that would handle some sort of quoting? > (...) > If you ignore that case, it's possible character by character with > a bit of extra state for quotes, nested parentheses, etc. (as that's > what zsh did for two decades) but you're going to need some incredibly > sophisticated regular expression involving recursion to replace that. Yes I should state that I'm aware it is not possible. I look for a best possible solution. Fast-syntax-highlighting now supports colorizing of command substitution $( ... ), it is called recursively on it. The point is that 90% of uses will be colored good with my current pattern: inputs=( ${(0)${(S)__buf[1,110]//(#b)*\$\((?#)([^\\\"]\)|(#e))/${mbegin[1]};${match[1]}${match[2]%\)}${__nul}}%$__nul*} ) The meaningful bit in above is: \$\((?#)([^\\\"]\)|(#e)). Match $(, then look for unquoted (not \), not ")) closing ) or for end of whole string. I utilize (S) non-greedy matching, and the (0)/$nul trick to handle multiple substitutions in one command line.The effect is already quite nice: http://psprint.blinkenshell.org/cmdsubst.png So the point is, the glob can be hacky and imperfect, if it holds some valuable solutions then syntax-highlighting user is at better position. Any uplifts to my current pattern are welcomed. -- Best regards, Sebastian Gniazdowski