Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to best match $( ... ) in a string
- X-seq: zsh-users 23418
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: How to best match $( ... ) in a string
- Date: Fri, 1 Jun 2018 12:56:13 +0200
- Cc: Zsh Users <zsh-users@xxxxxxx>
- 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==
- In-reply-to: <20180601095018eucas1p1662451fd258f46cdfdee319db48458a8~0AGeNx_UX2206222062eucas1p1m@eucas1p1.samsung.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: <CGME20180601084641epcas5p1ca4cd48fa463123bbe980d132fd19473@epcas5p1.samsung.com> <CAKc7PVANEoKJ0-R0i_zr6PoZYgzP8hYAtrTeyEKM-o4HoBr1rQ@mail.gmail.com> <20180601095018eucas1p1662451fd258f46cdfdee319db48458a8~0AGeNx_UX2206222062eucas1p1m@eucas1p1.samsung.com>
On 1 June 2018 at 11:50, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Fri, 1 Jun 2018 10:44:58 +0200
> Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author